Skip to content

Instantly share code, notes, and snippets.

@codeguru42
Created May 4, 2014 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeguru42/a2996142c36ccdc04dbc to your computer and use it in GitHub Desktop.
Save codeguru42/a2996142c36ccdc04dbc to your computer and use it in GitHub Desktop.
FIBD
fibd n m = sum $ fibd' !! (n-1)
where fibd' = [[fibd'' i j | i <- [0..m]] | j <- [0..n]]
-- `fibd'' i j` is the number of rabbits which are `i` months old after `j` months since the first generation
fibd'' 0 0 = 1
fibd'' _ 0 = 0
fibd'' 0 j = sum . tail $ fibd' !! (j-1)
fibd'' i j = fibd' !! (j-1) !! (i-1)
main = do
print $ fibd n m
where n = 6
m = 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment