1. #!/usr/bin/python
  2. from sys import argv
  3. numDays = int(argv[1])
  4. 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]
  5. def findClosestSolution(lst, curMin):
  6.     count = len(lst)
  7.     if count == numDays:
  8.         if abs(sum(lst)) < curMin:
  9.             return lst
  10.         return None
  11.     minSeq = None
  12.     for idx in range(0, count):
  13.         lstCopy = lst[:]
  14.         del lstCopy[idx]
  15.         retval = findClosestSolution(lstCopy, curMin)
  16.         if retval:
  17.             curMin = abs(sum(retval))
  18.             minSeq = retval
  19.             if curMin == 0:
  20.                 return minSeq
  21.     return minSeq
  22.            
  23. print findClosestSolution(wins, 99999)
  24. View this file Here (Right Click and save As)