
21 May
2007
21 May
'07
4:34 p.m.
Mark.Carroll@Aetion.com (Mark T.B. Carroll) writes:
alg n m = case signum m of -1 -> [] 0 -> [[]] 1 -> [ x : xs | x <- [1..n], xs <- alg n (m - x) ]
FWIW it's faster if you do some memoising: algMemo n m = lookupMemo m where memo = [[]] : map helper [1..m] lookupMemo m = if m < 0 then [] else memo !! m helper m' = [ x : xs | x <- [1..n], xs <- lookupMemo (m' - x) ] -- Mark