Created
February 17, 2015 01:43
-
-
Save amonshiz/9094ea068a611513607a 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
nextMonth :: [Int] -> [Int] | |
nextMonth xs = (sum $ tail xs) : (init xs) | |
numRabbits :: Int -> Int -> Int | |
numRabbits _ 0 = 0 | |
numRabbits _ 1 = 1 | |
numRabbits m n = sum $ foldl (\prevM _ -> nextMonth prevM) (1 : take (m-1) (repeat 0)) [2..n] | |
main = do | |
n <- readLn :: IO Int | |
m <- readLn :: IO Int | |
putStrLn . show $ numRabbits m n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment