Created
December 25, 2015 05:00
-
-
Save tanutarou/910e41991f22b77b55b4 to your computer and use it in GitHub Desktop.
Penney's game simulation
This file contains 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 numpy as np | |
N = 10000 | |
winfreq = np.array([0, 0]) | |
playerA = "111" | |
playerB = "011" | |
for i in xrange(N): | |
res = [2, 2, 2] | |
while True: | |
res.pop(0) | |
coin = np.random.randint(2) | |
res.append(coin) | |
bin_res = "".join(map(str, res)) | |
if bin_res == playerA: | |
winfreq[0] += 1 | |
break | |
elif bin_res == playerB: | |
winfreq[1] += 1 | |
break | |
winrate = winfreq * 1.0 / N | |
print "win rate:" | |
print winrate | |
print "playerB / playerA = ", winrate[1] / winrate[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment