Skip to content

Instantly share code, notes, and snippets.

@yattom
Last active August 7, 2018 04:31
Show Gist options
  • Save yattom/f546503184587796243d21f3f1ef49e4 to your computer and use it in GitHub Desktop.
Save yattom/f546503184587796243d21f3f1ef49e4 to your computer and use it in GitHub Desktop.
show distribution of roll of dices
def dice_dist(n):
d = [0]
for i in range(n):
d = [b + r for b in d for r in range(1, 7)]
for r, c in {n: d.count(n) for n in d}.items():
print(f"{r:>3} {c/6**n:>5.1%} {'*'*c}")
>>> dice_dist(1)
1 16.7% *
2 16.7% *
3 16.7% *
4 16.7% *
5 16.7% *
6 16.7% *
>>> dice_dist(3)
3 0.5% *
4 1.4% ***
5 2.8% ******
6 4.6% **********
7 6.9% ***************
8 9.7% *********************
9 11.6% *************************
10 12.5% ***************************
11 12.5% ***************************
12 11.6% *************************
13 9.7% *********************
14 6.9% ***************
15 4.6% **********
16 2.8% ******
17 1.4% ***
18 0.5% *
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment