Skip to content

Instantly share code, notes, and snippets.

@nth10sd
Created March 1, 2016 03:15
Show Gist options
  • Save nth10sd/d7a9fe99eeeb3aaf8797 to your computer and use it in GitHub Desktop.
Save nth10sd/d7a9fe99eeeb3aaf8797 to your computer and use it in GitHub Desktop.
import itertools
import operator
import functools
# Variables
src = [
68.92,
66.63,
36.66,
24.74,
49.27,
83.79,
83.92,
98.47,
]
currList = []
currVal = 0
maxVal = 163.11
maxNum = 5
for i in xrange(maxNum):
for j in itertools.permutations(src, i + 1):
addI = functools.reduce(operator.add, j) # Add all numbers in the list
if addI > currVal and addI <= maxVal:
currList = j
currVal = addI
print 'Minimum deviation: %0.2f' % (maxVal - currVal)
print '%s: %0.2f' % (currList, currVal)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment