Subset sum problem: Difference between revisions
Content added Content deleted
(→{{header|Haskell}}: non-bruteforce) |
|||
Line 501: | Line 501: | ||
None bruteforce: the list of numbers used here are different, and difficult for a bruteforce method. |
None bruteforce: the list of numbers used here are different, and difficult for a bruteforce method. |
||
<lang haskell>subsum |
<lang haskell>subsum = foldl sub_ [(0,[])] where |
||
sub_ a |
sub_ a x = merge a $ map f a where |
||
f (a,l) = (a+x, l++[x]) |
|||
f x (a,l) = (a+x, l++[x]) |
|||
-- keep list of sums sorted. Don't use standard sort! |
-- keep list of sums sorted. Don't use standard sort! |