Need help setting up arrays for Galton box simulation?

  • Context: Java 
  • Thread starter Thread starter irresistible
  • Start date Start date
  • Tags Tags
    Arrays Java
Click For Summary
SUMMARY

The discussion focuses on implementing a Galton box simulation in Java, where balls are dropped and have a 50% chance of falling left or right at each level. The user seeks guidance on setting up arrays to represent the slots where balls accumulate. The recommended approach involves using a structure similar to Pascal's triangle, where each slot's position corresponds to its row and column. The total number of slots required is calculated using the formula n(n+1)/2, where n is the number of rows.

PREREQUISITES
  • Basic understanding of Java programming
  • Familiarity with arrays in Java
  • Knowledge of probability concepts
  • Understanding of Pascal's triangle structure
NEXT STEPS
  • Implement a Java program to simulate the Galton box using arrays
  • Research Java array initialization and manipulation techniques
  • Explore probability distributions and their applications in simulations
  • Learn about graphical representation of simulations in Java
USEFUL FOR

Beginner Java developers, educators teaching probability concepts, and anyone interested in simulation programming and data structures.

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.
 

Similar threads

  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 29 ·
Replies
29
Views
6K
Replies
2
Views
1K
  • · Replies 49 ·
2
Replies
49
Views
12K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
11
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K