Subset sum problem: Difference between revisions

m
m (→‎{{header|Haskell}}: make it find sums other than 0, too)
Line 501:
 
None bruteforce: the list of numbers used here are different, and difficult for a bruteforce method.
<lang haskell>subsum wantw = snd.head.filter ((==w).fst).(++[(w,[])]).foldl sub_s [(-want0,[])] where
where
sub_ a x = merge a $ map f a where
s a x = merge a $ map f a where f (a,l) = (a+x, l++[x])
-- keep list of sums sorted and unique
Line 517:
-216, 373, -185, -402, 156, -402, -61, -31, 902 ]
main = print $ snd.head.filter ((==0).fst) $ subsum 0 items</lang>
{{out}}
<pre>
Anonymous user