Skip to content

Instantly share code, notes, and snippets.

@mcpower
Created December 5, 2015 09:15
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 mcpower/0f678d5b278b1fa8d229 to your computer and use it in GitHub Desktop.
Save mcpower/0f678d5b278b1fa8d229 to your computer and use it in GitHub Desktop.
L = [int(x) for x in "1307 2716 3449 2758 4597 5191 1465 2259 2829 3004".split()]
N = 20000
array = [[]] + [None for i in range(N-1)]
minimum, route = float("inf"), None
for num in L:
todo = []
for index in range(N):
if array[index] is not None:
if index + num >= N:
if index + num < minimum:
minimum, route = index + num, array[index] + [num]
break
if array[index+num] is None:
todo.append(index)
for index in todo:
array[index+num] = array[index] + [num]
print(minimum, route)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment