fork(3) download
  1. main = print $ partitions 20 [16,8,4,2,1]
  2.  
  3. partitions 0 xs = [[]]
  4. partitions _ [] = []
  5. partitions n (xxs@(x:xs)) | n < 0 = []
  6. | otherwise = (map (x:) (partitions (n-x) xxs)) ++ partitions n xs
Success #stdin #stdout 0s 4712KB
stdin
Standard input is empty
stdout
[[16,4],[16,2,2],[16,2,1,1],[16,1,1,1,1],[8,8,4],[8,8,2,2],[8,8,2,1,1],[8,8,1,1,1,1],[8,4,4,4],[8,4,4,2,2],[8,4,4,2,1,1],[8,4,4,1,1,1,1],[8,4,2,2,2,2],[8,4,2,2,2,1,1],[8,4,2,2,1,1,1,1],[8,4,2,1,1,1,1,1,1],[8,4,1,1,1,1,1,1,1,1],[8,2,2,2,2,2,2],[8,2,2,2,2,2,1,1],[8,2,2,2,2,1,1,1,1],[8,2,2,2,1,1,1,1,1,1],[8,2,2,1,1,1,1,1,1,1,1],[8,2,1,1,1,1,1,1,1,1,1,1],[8,1,1,1,1,1,1,1,1,1,1,1,1],[4,4,4,4,4],[4,4,4,4,2,2],[4,4,4,4,2,1,1],[4,4,4,4,1,1,1,1],[4,4,4,2,2,2,2],[4,4,4,2,2,2,1,1],[4,4,4,2,2,1,1,1,1],[4,4,4,2,1,1,1,1,1,1],[4,4,4,1,1,1,1,1,1,1,1],[4,4,2,2,2,2,2,2],[4,4,2,2,2,2,2,1,1],[4,4,2,2,2,2,1,1,1,1],[4,4,2,2,2,1,1,1,1,1,1],[4,4,2,2,1,1,1,1,1,1,1,1],[4,4,2,1,1,1,1,1,1,1,1,1,1],[4,4,1,1,1,1,1,1,1,1,1,1,1,1],[4,2,2,2,2,2,2,2,2],[4,2,2,2,2,2,2,2,1,1],[4,2,2,2,2,2,2,1,1,1,1],[4,2,2,2,2,2,1,1,1,1,1,1],[4,2,2,2,2,1,1,1,1,1,1,1,1],[4,2,2,2,1,1,1,1,1,1,1,1,1,1],[4,2,2,1,1,1,1,1,1,1,1,1,1,1,1],[4,2,1,1,1,1,1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