Last active
January 4, 2016 22:09
-
-
Save AndrasKovacs/8686121 to your computer and use it in GitHub Desktop.
DP solution to SICP Chapter 1.2 coin change problem.
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
coinChange :: [Int] -> [Int] | |
coinChange = foldr go (1: repeat 0) where | |
go coin xs = xs' where | |
(a, b) = splitAt coin xs | |
xs' = a ++ zipWith (+) xs' b | |
main = print $ coinChange [1,5,10,25,50] !! 100 -- prints 292 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what I meant was this
although it doesn't scale well, like your version in this gist does.