Created
November 3, 2020 01:31
-
-
Save rsha256/5f7965f327459910458207bcad1d0d14 to your computer and use it in GitHub Desktop.
simple coin toss visualizer for a fair coin's sample space
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def product(*iters): | |
def loop(prod, first=[], *rest): | |
if not rest: | |
for x in first: | |
yield prod + (x, ) | |
else: | |
for x in first: | |
yield from loop(prod + (x, ), *rest) | |
yield from loop((), *iters) | |
def toss_coins_h(n): | |
sides = ['H', 'T'] | |
coins = [sides] * n | |
yield from product(*coins) | |
def toss_coins(n): | |
for i in toss_coins_h(n): | |
print(i) | |
toss_coins(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment