Need help setting up arrays for Galton box simulation?

  • Context: Java 
  • Thread starter Thread starter irresistible
  • Start date Start date
  • Tags Tags
    Arrays Java
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 4K views
irresistible
Messages
15
Reaction score
0
I'm new in java and
I'm trying to come up with a program that stimulates the bean machine(also known as Galton box)
Balls are dropped from the opening of the board. Everytime a ball hits, there is a 50% chance to fall to left and 50% chance to fall to the right. the piles of balls are accumulated in the slots at the bottom of the board.

I'm just trying to set up my algorithm, but I don't know how to set up my arrays. i.e, the entreis in the arrays, the Givens, results, etc.

This is a Galton box and how it works in case you don't know:
http://upload.wikimedia.org/wikipedia/commons/thumb/7/78/Galton_Box.svg/507px-Galton_Box.svg.png

I just don't know where to start.. how to set up my arrays.
Any help is appreciated.:smile:
 
Physics news on Phys.org
You can store the data in the form of a Pascal's triangle.
The top slot will be numbered 1.
The second row will have slots 2 and 3, third row 4,5,6, and so on.

Code:
       1
      2 3
     4 5 6
    7 8 9 10
This way, the marble/ball falls in slot one will have equal chances of falling into slots 2 or 3.
From 2 (row 2) there will be equal chances of falling into 4 or 5, and from 5 (row 3) it will have equal chances for falling into slots 8 or 9, and so on.
In short, from slot m on row n, the two possible destination slots are m+n and m+n+1.
You will only need to set up an array to store all the slots, start with slot one, keep track of the row number and keep the ball falling! The number of slots required is n(n+1)/2, where n is the number of rows.