Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import defaultdict
- heads, tails= defaultdict(int, {0: 1}), defaultdict(int, {0: 1})
- n=101
- for i in range(2, n):
- new_heads, new_tails = defaultdict(int), defaultdict(int)
- for key, value in tails.items():
- new_heads[key] = value
- new_tails[key] = value
- for key, value in heads.items():
- new_heads[key + 1] += value
- new_tails[key - 1] += value
- heads, tails = new_heads, new_tails
- merged = [*heads.items(), *tails.items()]
- awins = sum(value for key, value in merged if key > 0)
- bwins = sum(value for key, value in merged if key < 0)
- ties = sum(value for key, value in merged if key == 0)
- print(f"n: {i}, awin = {awins/2**i*100}, bwin = {bwins/2**i*100}, tie = {ties/2**i*100}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement