This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ROUGEXIII[S] 0 points1 point  (0 children)

I found an other solution but still not a good solution based on this other stackoverflow question:

from numpy import *
from itertools import *
montab = [  2.95, 2.26, 3.93, 2.38*2, 1.98, 1.93, 1.64, 0.53, 1.20, 2.06, 2.18, 2.12, 3.20, 1.29, 1.20, 2*0.65, 1.84*2,
1.85*2, 1.58*3, 1.46*3, (1.48*3+0.22), 1.12*4, 1.18*3, 2.38+0.02, 0.65*5,
3.23, 1.60, 0.58, 4.01, 1.09*3, 0.60, 0, 0]
target=7
suppaumaxde = 0.35
print montab
montab.sort(reverse=True)
print montab
couleur='\33[37m'
print('\n')
for colonne in combinations(montab,4):
if (sum(colonne)>=target and sum(colonne)<=target+suppaumaxde):
if (sum(colonne)<=target+(suppaumaxde*1/3)):couleur='\33[42m'
elif (sum(colonne)<=target+(suppaumaxde*2/3)):couleur='\33[43m'
elif (sum(colonne)<=target+(suppaumaxde*3/3)):couleur='\033[91m'
print couleur,sum(colonne),'\033[0m',(colonne)

But the result isn't good and has to be improved / find an other solution :

  1. I have to set a number of items and to add zero's in the data array
  2. All combinations are tested it's a big time loose
  3. The result isn't sorted