#!/usr/bin/python
from sys import argv
numDays = int(argv[1])
wins = [-50,-21,13,171,14,-42,-58,109,4,7,-23,-44,-98,-121,101,33,87,-121,-40,-65,43,54,-45,-12,-12,38,25,3,7,8]
def findClosestSolution(lst, curMin):
count = len(lst)
if count == numDays:
if abs(sum(lst)) < curMin:
return lst
return None
minSeq = None
for idx in range(0, count):
lstCopy = lst[:]
del lstCopy[idx]
retval = findClosestSolution(lstCopy, curMin)
if retval:
curMin = abs(sum(retval))
minSeq = retval
if curMin == 0:
return minSeq
return minSeq
print findClosestSolution(wins, 99999)
- View this file Here (Right Click and save As)