Created
May 2, 2010 10:34
-
-
Save eagletmt/387050 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
import Data.Array | |
import Data.Array.ST | |
import Control.Monad (forM_, liftM2) | |
main = print $ exchanges coins 10000 ! 10000 | |
where | |
coins = [1, 5, 10, 50, 100, 500, 1000, 2000, 5000, 10000] | |
exchanges :: (Ix a, Enum a, Num a, Num e) => [a] -> a -> Array a e | |
exchanges cs n = runSTArray $ do | |
a <- newArray (0,n) 0 | |
writeArray a 0 1 | |
forM_ cs $ \c -> | |
forM_ [c .. n] $ \i -> | |
liftM2 (+) (readArray a (i-c)) (readArray a i) >>= writeArray a i | |
return a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment