Java Need help setting up arrays for Galton box simulation?

  • Thread starter Thread starter irresistible
  • Start date Start date
  • Tags Tags
    Arrays Java
AI Thread Summary
To simulate a Galton box in Java, start by setting up an array to represent the slots where balls accumulate. Each ball has a 50% chance of falling left or right at each row, which can be modeled using a structure similar to Pascal's triangle. The top slot is numbered 1, with subsequent rows expanding to accommodate the falling balls, where the destination slots for a ball from slot m on row n are m+n and m+n+1. The total number of slots needed is calculated using the formula n(n+1)/2, where n is the number of rows. This approach will effectively track the balls as they fall through the slots.
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:
 
Technology 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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top