Skip to content

Instantly share code, notes, and snippets.

@livinginformation
Created August 3, 2015 07:25
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 livinginformation/03da477a53563688460e to your computer and use it in GitHub Desktop.
Save livinginformation/03da477a53563688460e to your computer and use it in GitHub Desktop.
import random
def init_game():
global stack, wallet, max_taken
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 passe():
stack.pop(0)
def oracle(m):
next = stack[:m]
return sum(next)/len(next)
def test(algo, N=50):
results = []
for rep in range(N):
init_game()
for i in range(10000):
algo()
results.append(wallet)
print(sorted(results)[N//2])
#Simplist algo, always takes
def algo_simple():
take()
test(algo_simple)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment