Haskell - counting number of recursions
haskell
Solution
recursions :: Integer -> Integer
recursions 0 = 0
recursions 1 = 0
recursions n = recursions (n-1) + recursions (n-2) + 2
For the base cases, there are no recursions, for everything else, we have two direct recursive calls and those that are invoked from the two.
You can also re-use the `fibonacci` code,
recursions n = 2*fibonacci (n+1) - 2
Problem
I have a simple function that calculates the n-th fibonnaci number below: ``` fibonacci :: Integer -> Integer fibonacci 0 = 0 fibonacci 1 = 1 fibonacci n = (fibonacci (n-1) ) + (fibonacci (n-2)) ``` But i am interested in a way to count the number of recursions of this function. Any ideas how to do it?