Skip to content

Instantly share code, notes, and snippets.

@randylubin
Last active October 2, 2015 03:18
Show Gist options
  • Save randylubin/2160209 to your computer and use it in GitHub Desktop.
Save randylubin/2160209 to your computer and use it in GitHub Desktop.
Unfair Flip Solution
import random
def fairFlip():
return random.randrange(2)
startingOdds = .625
def unfairFlip(odds):
if odds >= .5:
if fairFlip() == 1:
return 1
else:
return unfairFlip((odds-.5)*2)
else:
if fairFlip() == 0:
return 0
else:
return unfairFlip(odds*2)
tally = 0
flips = 1000000
for i in range(flips):
if unfairFlip(startingOdds):
tally += 1
print tally/float(flips/100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment