PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from random import randint
from collections import Counter
'The Galton Board is triangular shaped with pegs on the board and slots at the bottom. Balls are placed in at the very top and hit the first peg causing them to either bounce left or right where they will meet another peg with the same choice. They continue to do this until they reach the bottom and enter a slot. The more balls and slots there are, the more we can see the natural bell-shaped curve that forms of normal and binomial distribution. Change the "amt" of balls and the "base" number of slots! FYI: The slots are printed sideways in my example and each "o" represents 1 ball.'
nums = []
amt = 100 #number of balls
base = 11 #number of base slots
offset = 0 #lowest slot number (don't change unless needed for statistical purposes)
for i in range(amt):
num = 0
for j in range(base-1):
lr = randint(0,1)
num += lr
nums.append(num)
nums = Counter(nums)
for i in range(base):
if i not in nums:
nums[i] = 0
keys = sorted(nums.keys())
bigv = 0
bigk = 0
for i in keys:
v = str(nums[i])
k = str(i+offset)
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run