Created
November 27, 2011 14:06
-
-
Save axiomsofchoice/1397603 to your computer and use it in GitHub Desktop.
Experimental mathematics for November 2011 London MathsJam
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
#!/usr/bin/env python | |
"""This piece of experimental mathematics came out of a discussion at the November 2011 | |
London MathsJam sparked by a Google Plus post from Randall Munroe https://plus.google.com/111588569124648292310/posts/dv9Fi45h91T | |
Code by @axiomsofchoice with help from other MathsJam attendees, including @Samuel_Hansen | |
""" | |
import random | |
n_trials = 1000000 | |
def genpair(n,val_i): | |
choice = random.gauss(mu=0.0, sigma=1.0) | |
if choice > 0: | |
return (n,2*n) | |
else: | |
return (n,n/2) | |
def random_tuple_item(first,second): | |
choice = random.gauss(mu=0.0, sigma=1.0) | |
if choice > 0: | |
return first | |
else: | |
return second | |
first_car_val = 10 | |
examples = [genpair(first_car_val,i) for i in range(n_trials)] | |
#card_sum = reduce(lambda x, y: x+y, [for examples) | |
#print "Example: ", examples | |
chosen_cards = [random_tuple_item(i,j) for i,j in examples] | |
#print "Card choices: ", chosen_cards | |
print "Sum of example second card for %s trials: %s" % (n_trials, reduce(lambda x, y: x+y, chosen_cards) / n_trials) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment