Advertisement
icarussiano

exact

Mar 18th, 2024
737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. from collections import defaultdict
  2. heads, tails= defaultdict(int, {0: 1}), defaultdict(int, {0: 1})
  3. n=101
  4. for i in range(2, n):
  5.     new_heads, new_tails = defaultdict(int), defaultdict(int)
  6.     for key, value in tails.items():
  7.         new_heads[key] = value
  8.         new_tails[key] = value
  9.     for key, value in heads.items():
  10.         new_heads[key + 1] += value
  11.         new_tails[key - 1] += value
  12.     heads, tails = new_heads, new_tails
  13.     merged = [*heads.items(), *tails.items()]
  14.     awins = sum(value for key, value in merged if key > 0)
  15.     bwins = sum(value for key, value in merged if key < 0)
  16.     ties = sum(value for key, value in merged if key == 0)
  17.     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