Subset sum problem: Difference between revisions

m
(→‎{{header|Haskell}}: non-bruteforce)
Line 501:
 
None bruteforce: the list of numbers used here are different, and difficult for a bruteforce method.
<lang haskell>subsum ls = foldl sub_ [(0,[])] ls where
sub_ a []x = merge a $ map f a where
sub_ f (a (x:xs,l) = sub_ (merge a+x, $ map (f l++[x]) a) xs
f x (a,l) = (a+x, l++[x])
 
-- keep list of sums sorted. Don't use standard sort!
Anonymous user