Created
September 16, 2024 12:05
-
-
Save vedgar/d0aedac84f2fdb07fb0b8fd56801c858 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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