Last active
December 18, 2015 21:38
-
-
Save WillNess/5848411 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| -- http://stackoverflow.com/questions/17242480/determining-ways-of-splitting-change | |
| -- the author writes: | |
| -- assumes the denominations are distinct. If they aren't, | |
| -- ((there will be some dupicates present in the result produced)) | |
| change :: (Num a, Ord a) => [a] -> a -> [[a]] | |
| change ds@ ~(d:t) sum | |
| | sum==0 = [[]] | |
| | null ds = [] | |
| | otherwise = concat [map (d:) $ change ds $ sum-d | d <= sum] ++ change t sum | |
| -- my comment: | |
| -- `d` is either present in the change, or not. If it is, then we can take | |
| -- one `d` coin out of the change, so it must be possible to change (sum-d). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment