Skip to content

Instantly share code, notes, and snippets.

@comfly
Last active June 8, 2016 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save comfly/40fd1523cd14187972ac to your computer and use it in GitHub Desktop.
Save comfly/40fd1523cd14187972ac to your computer and use it in GitHub Desktop.
All summands combinations
summands 0 = []
summands n = [n]:concat [summandsOfTwo k (n - k) | k <- [1..n `quot` 2]]
where summandsOfTwo l r =
let le = map (r:) (summands l)
re = map (l:) (summands r)
in if l == r then le else le ++ re
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment