Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dailyIntake(caloricValue):
- sums = []
- diff_closest_sum = float(2000)
- # Closest difference to 2000
- from itertools import combinations as c
- for j in range(1, len(caloricValue)):
- for i in c(caloricValue, j):
- t = abs(sum(i) - 2000)
- if t < diff_closest_sum:
- sums = []
- sums.append(i)
- diff_closest_sum = t
- elif t == diff_closest_sum:
- sums.append(i)
- t = abs(sum(caloricValue) - 2000)
- if t < diff_closest_sum:
- sums = []
- sums.append(caloricValue)
- elif t == diff_closest_sum:
- sums.append(caloricValue)
- # Find indexes
- indexes = []
- idx = 0
- for x in sums:
- indexes.append([])
- temp = {(caloricValue[value], value):True for value in range(len(caloricValue))}
- for i in x:
- print temp
- for k in temp:
- if temp[k] and k[0] == i:
- indexes[idx].append(k[1])
- temp[k] = False
- break
- idx += 1
- t = []
- for i in indexes:
- t.append(''.join([str(x) for x in sorted(i)]))
- if len(t):
- return [int(x) for x in list(min(t))]
- return t
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement