Created
March 1, 2016 03:15
-
-
Save nth10sd/d7a9fe99eeeb3aaf8797 to your computer and use it in GitHub Desktop.
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
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