Simulate a Galton machine. Input should be: Levels (how many rows of pins are th
ID: 3550992 • Letter: S
Question
Simulate a Galton machine.
Input should be:
Levels (how many rows of pins are there. Allow up to 100)
Balls (how many balls will be dropped into the machine)
Output: How many of the balls dropped ended up in each of the slots at the bottom.(The number of slots will be one more than the number of levels)
Since the balls will always hit the same pin on level 1, there need only be one pin at level one. And since it will go left or right one space and hit a pin at level 2, there need only be two pins on that level, and so on. Each level will then have one more pin than the level above. Use an array to count the number of balls falling into each slot. Use a loop to simulate a ball hitting a pin at each level. Go through this loop for each ball. simulate using pin numbers.
Number the pins left to right starting at level 1:
1
2 3
4 5 6 7
8 9 1011
12 13 14 15
Go through a loop as many times as there are levels and calculate which pin they will hit next, randomly going left or right. When the last level is reached, into a slot it goes.