Created
April 11, 2014 22:37
-
-
Save cep21/10507188 to your computer and use it in GitHub Desktop.
Odds of predicting a 49.5 % coin is worse than a 50% coin
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 | |
def simulate(a, b, iterations): | |
acount = bcount = 0 | |
for i in xrange(iterations): | |
vala = random.uniform(0, a) | |
valb = random.uniform(0, b) | |
if vala > valb: | |
acount+=1 | |
elif vala < valb: | |
bcount += 1 | |
if acount > bcount: | |
return True | |
else: | |
return False | |
def run_simulation(a, b, iterations, simulation_times): | |
c = 0.0 | |
for i in xrange(simulation_times): | |
if simulate(a, b, iterations): | |
c += 1 | |
print "At %f vs %f with %d iterations , I get %f over %f a %f of the time" % (a, b, iterations, a, b, c/simulation_times) | |
a = .495 | |
b = .50 | |
run_simulation(a, b, 10000, 10000) | |
run_simulation(a, b, 9000, 10000) | |
run_simulation(a, b, 8000, 10000) | |
run_simulation(a, b, 7000, 10000) | |
run_simulation(a, b, 6000, 10000) | |
run_simulation(a, b, 5000, 10000) | |
run_simulation(a, b, 4000, 10000) | |
run_simulation(a, b, 3000, 10000) | |
run_simulation(a, b, 2000, 10000) | |
run_simulation(a, b, 1000, 10000) | |
run_simulation(a, b, 500, 10000) | |
run_simulation(a, b, 100, 10000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment