Subset sum problem: Difference between revisions

Realize in MiniZinc
m (→‎{{header|REXX}}: added/changed comments and whitespace, re-arranged the list of words for a smaller footprint within the program.)
(Realize in MiniZinc)
Line 1,362:
{423, smokescreen}}.</pre>
 
=={{header|MiniZinc}}==
<lang MiniZinc>
%Subset sum. Nigel Galloway: January 6th., 2021.
enum Items={alliance,archbishop,balm,bonnet,brute,centipede,cobol,covariate,departure,deploy,diophantine,efferent,elysee,eradicate,escritoire,exorcism,fiat,filmy,flatworm,gestapo,infra,isis,lindholm,markham,mincemeat,moresby,mycenae,plugging,smokescreen,speakeasy,vein};
array[Items] of int: weight=[-624,-915,397,452,870,-658,362,590,952,44,645,54,-326,376,856,-983,170,-874,503,915,-847,-982,999,475,-880,756,183,-266,423,-745,813];
var set of Items: selected;
var int: wSelected=sum(n in selected)(weight[n]);
constraint wSelected=0;
</lang>
{{out}}
<pre>
selected = {alliance, archbishop, balm, bonnet, brute, centipede, cobol, covariate, departure, deploy, diophantine, efferent, elysee, eradicate, escritoire, exorcism, fiat, filmy, flatworm, mincemeat, plugging, speakeasy};
----------
Finished in 185msec
</pre>
=={{header|Modula-2}}==
<lang modula2>MODULE SubsetSum;
2,172

edits