Created
December 13, 2016 15:39
-
-
Save n6g7/518151cc7711af3f9f6c5fe940756079 to your computer and use it in GitHub Desktop.
Numberphile guesser
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 random | |
n = 10000 | |
def randomize(): | |
return random.normalvariate(0, 100) | |
def guess(): | |
a = randomize() | |
b = randomize() | |
assert a != b | |
# Choice artefact | |
k = randomize() | |
if a>k: | |
# We'll suppose A is the largest | |
return a > b | |
elif a<k: | |
# We'll suppose A is the smallest | |
return a < b | |
success = 0 | |
count = 0 | |
for i in range(n): | |
try: | |
if guess(): | |
success += 1 | |
count += 1 | |
except: | |
continue | |
print "guesses : %s" % count | |
print "successes : %s (%s%%)" % (success, (success*100./n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment