Created
January 8, 2016 14:07
-
-
Save Noxville/ed957e39c75e003c6aa9 to your computer and use it in GitHub Desktop.
Salesman Ridder Problem on Five Thirty Eight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(Outputs 1.2).