Subset sum problem: Difference between revisions

(Added Sidef)
Line 1,629:
'smokescreen': 423,
'speakeasy': -745>
</pre>
 
=={{header|zkl}}==
{{trans|C}}
<lang zkl>var items=T(
T("alliance", -624), T("archbishop", -915), T("balm", 397),
T("bonnet", 452), T("brute", 870), T("centipede", -658),
T("cobol", 362), T("covariate", 590), T("departure", 952),
T("deploy", 44), T("diophantine", 645), T("efferent", 54),
T("elysee", -326), T("eradicate", 376), T("escritoire", 856),
T("exorcism", -983), T("fiat", 170), T("filmy", -874),
T("flatworm", 503), T("gestapo", 915), T("infra", -847),
T("isis", -982), T("lindholm", 999), T("markham", 475),
T("mincemeat", -880), T("moresby", 756), T("mycenae", 183),
T("plugging", -266), T("smokescreen", 423), T("speakeasy", -745),
T("vein", 813));
fcn subSum(set,i,weight){
if(i and not weight){
itms:=i.pump(List,'wrap(n){ items[set[n]][0] });
println(itms.len(),": ",itms.concat(","));
throw(Exception.TheEnd);
}
foreach j in ([i and set[i-1] + 1 or 0 .. items.len()-1]){
set[i]=j;
self.fcn(set, i+1, weight + items[j][1]);
}
}
 
set:=List.createLong(items.len(),0);
try{ subSum(set,0,0); }catch(TheEnd){}</lang>
{{out}}
<pre>
22: alliance,archbishop,balm,bonnet,brute,centipede,cobol,covariate,departure,deploy,diophantine,efferent,elysee,eradicate,escritoire,exorcism,fiat,filmy,flatworm,mincemeat,plugging,speakeasy
</pre>
Anonymous user