Skip to content

Instantly share code, notes, and snippets.

@Noxville
Created January 8, 2016 14:07
Show Gist options
  • Save Noxville/ed957e39c75e003c6aa9 to your computer and use it in GitHub Desktop.
Save Noxville/ed957e39c75e003c6aa9 to your computer and use it in GitHub Desktop.
Salesman Ridder Problem on Five Thirty Eight
#!/usr/bin/python
from itertools import permutations
from math import e, ceil
cutoff = int(ceil(5. / e)) # for verbosity - it's 2
def solve(left, best):
for remaining in left:
if remaining < best:
return remaining
return left[-1] # Forced to take the last offer
paid = 0
for seq in permutations('01234'):
offers = map(int, seq)
paid += solve(offers[cutoff:], min(offers[:cutoff]))
print paid / 120.
@Noxville
Copy link
Author

Noxville commented Jan 8, 2016

(Outputs 1.2).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment