Advertisement
Guest User

instabot3

a guest
Jun 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. def dailyIntake(caloricValue):
  2.     sums = []
  3.     diff_closest_sum = float(2000)
  4.    
  5.     # Closest difference to 2000
  6.     from itertools import combinations as c
  7.     for j in range(1, len(caloricValue)):
  8.         for i in c(caloricValue, j):
  9.             t = abs(sum(i) - 2000)
  10.             if t < diff_closest_sum:
  11.                 sums = []
  12.                 sums.append(i)
  13.                 diff_closest_sum = t
  14.             elif t == diff_closest_sum:
  15.                 sums.append(i)
  16.    
  17.     t = abs(sum(caloricValue) - 2000)
  18.     if t < diff_closest_sum:
  19.         sums = []
  20.         sums.append(caloricValue)
  21.     elif t == diff_closest_sum:
  22.         sums.append(caloricValue)
  23.    
  24.     # Find indexes
  25.     indexes = []
  26.     idx = 0
  27.     for x in sums:
  28.         indexes.append([])
  29.         temp = {(caloricValue[value], value):True for value in range(len(caloricValue))}
  30.         for i in x:
  31.             print temp
  32.             for k in temp:
  33.                 if temp[k] and k[0] == i:
  34.                     indexes[idx].append(k[1])
  35.                     temp[k] = False
  36.                     break
  37.         idx += 1          
  38.    
  39.     t = []
  40.     for i in indexes:
  41.         t.append(''.join([str(x) for x in sorted(i)]))
  42.     if len(t):
  43.         return [int(x) for x in list(min(t))]
  44.     return t
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement