Skip to content

Instantly share code, notes, and snippets.

@vedgar
Created September 16, 2024 12:05
Show Gist options
  • Save vedgar/d0aedac84f2fdb07fb0b8fd56801c858 to your computer and use it in GitHub Desktop.
Save vedgar/d0aedac84f2fdb07fb0b8fd56801c858 to your computer and use it in GitHub Desktop.
import random, enum, collections
trials, coins, heads, consecutive = 10**5, 100, 2, False
Coin, sequences, wins = enum.Enum('Coin', ['H', 'T']), {}, collections.Counter()
for trial in range(trials):
result = {}
sequences['Alice'] = S = random.choices(list(Coin), k=coins)
sequences['Bob'] = S[::2] + S[1::2]
for person, sequence in sequences.items():
seen = 0
for index, coin in enumerate(sequence, 1):
if coin is Coin.H: seen += 1
elif consecutive: seen = 0
if seen == heads: break
result[person] = index
if result['Alice'] < result['Bob']: wins['Alice'] += 1
elif result['Bob'] < result['Alice']: wins['Bob'] += 1
print(wins)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment