Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Help with arrays in java.

  1. Feb 13, 2009 #1
    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:
     
  2. jcsd
  3. Feb 13, 2009 #2
    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 (Text):
           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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Help with arrays in java.
  1. Help with array (Replies: 5)

Loading...