Skip to content

Instantly share code, notes, and snippets.

@tedtieken
Created September 15, 2013 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tedtieken/6567112 to your computer and use it in GitHub Desktop.
Save tedtieken/6567112 to your computer and use it in GitHub Desktop.
Demonstrating that the two envelopes paradox is actually a fallacy.
import random
envs = [10.0, 20.0]
rounds = 10000
total_stay = 0
for x in xrange(rounds):
  t_envs = envs[:]
  random.shuffle(t_envs)
  choice = t_envs.pop()
  total_stay += choice
total_switch = 0
for x in xrange(rounds):
  t_envs = envs[:]
  random.shuffle(t_envs)
  choice = t_envs.pop()
  new_choice = t_envs.pop()
  total_switch += new_choice
d_rounds = rounds * 1.0
print total_stay / d_rounds 
print total_switch / d_rounds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment