Skip to content

Instantly share code, notes, and snippets.

@milesrout
Last active August 29, 2015 14:04
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 milesrout/da3c80f895e03b22385c to your computer and use it in GitHub Desktop.
Save milesrout/da3c80f895e03b22385c to your computer and use it in GitHub Desktop.
# Determine whether, in any state, the expected chosen prize is greater than the maximum prize
from itertools import combinations
from math import log, exp
cases = {1,10,100,1000}
maxprize = 200
s = set.union(*[set(combinations(cases, i)) for i in range(1, len(cases)+1)])
ss = sorted(s)
def pretty(set):
for combo in sorted(set):
print(', '.join(map(str, combo)))
ours = lambda c: float(sum(c)) / len(c)**2
his = lambda c: exp(sum(map(log, c)) / len(c))
comp = lambda c: max(ours(c), his(c)) > maxprize
def f(c, n=None):
if n is None:
n = len(c)
if his(c) > ours(c):
return any(acceptable(x) for x in combinations(c, n-1))
else:
return ours(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment