Skip to content

Instantly share code, notes, and snippets.

@amonshiz
Created February 17, 2015 01:43
Show Gist options
  • Save amonshiz/9094ea068a611513607a to your computer and use it in GitHub Desktop.
Save amonshiz/9094ea068a611513607a to your computer and use it in GitHub Desktop.
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