9 lines
371 B
Plaintext
9 lines
371 B
Plaintext
fcn addItem(old,[(nm,w,v,c)]){ // old:list:(cost of:,(name,#,...))
|
|
[1..c].reduce(fcn(list,i,nm,w,v,old){
|
|
wi,left,right:=w*i,list[0,wi],list[wi,*];
|
|
new:=old.apply('wrap([(val,itms)]){ T(val + v*i,itms.append(nm,i)) });
|
|
left.extend(right.zipWith( // inc
|
|
fcn([(v1,_)]a,[(v2,_)]b){ v1>v2 and a or b },new));
|
|
},old,nm,w,v,old);
|
|
}//--> new list
|