Skip to content

Instantly share code, notes, and snippets.

@orlp
Last active August 29, 2015 14:26
Show Gist options
  • Save orlp/f9b949d60c766430fe9c to your computer and use it in GitHub Desktop.
Save orlp/f9b949d60c766430fe9c to your computer and use it in GitHub Desktop.
import random
import math
def init_game():
global stack, wallet, max_taken, remaining
stack = list(range(1, 10001))
random.shuffle(stack)
wallet = max_taken = 0
def read():
return stack[0]
def take():
global wallet, max_taken
amount = stack.pop(0)
if amount > max_taken:
wallet += amount
max_taken = amount
def pass_envelope():
stack.pop(0)
def test(algo):
init_game()
for i in range(10000):
algo()
return wallet
def algo_dennis():
global turns
turns -= 1
if read() > turns:
take()
else:
pass_envelope()
s = []
for i in range(51):
turns = 10001
s.append(test(algo_dennis))
print(list(sorted(s))[25])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment