Last active
June 8, 2016 21:07
-
-
Save comfly/40fd1523cd14187972ac to your computer and use it in GitHub Desktop.
All summands combinations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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