Subset sum problem: Difference between revisions

m
m (syntax highlighting fixup automation)
m (→‎{{header|Wren}}: Minor tidy)
 
(One intermediate revision by one other user not shown)
Line 3,007:
=={{header|Wren}}==
{{trans|Kotlin}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
class Item {
Line 3,200:
isis -982
smokescreen 423
</pre>
 
=={{header|XPL0}}==
{{trans|C}}
<syntaxhighlight lang "XPL0">include xpllib; \for Print
def \Items\ Wd, Wt;
def N = 31;
int Set(N), Items;
 
proc SubSum(I, Weight);
int I, Weight, J;
[if I#0 & Weight=0 then
[for J:= 0 to I-1 do
Print("%s%s", if J then " " else "", Items(Set(J),Wd));
Print("\n");
exit;
];
for J:= if I#0 then Set(I-1)+1 else 0 to N-1 do
[Set(I):= J;
SubSum(I+1, Weight+Items(J,Wt));
];
];
 
[Items:= [
["alliance", -624],
["archbishop", -915],
["balm", 397],
["bonnet", 452],
["brute", 870],
["centipede", -658],
["cobol", 362],
["covariate", 590],
["departure", 952],
["deploy", 44],
["diophantine", 645],
["efferent", 54],
["elysee", -326],
["eradicate", 376],
["escritoire", 856],
["exorcism", -983],
["fiat", 170],
["filmy", -874],
["flatworm", 503],
["gestapo", 915],
["infra", -847],
["isis", -982],
["lindholm", 999],
["markham", 475],
["mincemeat", -880],
["moresby", 756],
["mycenae", 183],
["plugging", -266],
["smokescreen", 423],
["speakeasy", -745],
["vein", 813] ];
SubSum(0, 0);
]</syntaxhighlight>
{{out}}
<pre>
alliance archbishop balm bonnet brute centipede cobol covariate departure deploy diophantine efferent elysee eradicate escritoire exorcism fiat filmy flatworm mincemeat plugging speakeasy
</pre>
 
9,482

edits