I will introduce a method to solve this problem without even understanding the solution.
Assuming you are familiar with fibonacci numbers:
ghci> let fib = 0 : 1 : zipWith (+) fib (tail fib) ghci> take 16 fib [0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610]
And also familiar with the expression of a closed form:
ghci> let calcFib i = round (((1 + sqrt 5) / 2) ^ i / sqrt 5) ghci> map calcFib [0..15] [0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610]
And you will notice the similarities between ((1 + sqrt 5) / 2) n and (3 + sqrt 5) n .
From here one can guess that there probably exists a series similar to the fibonacci for calculating this.
But what series? So, you are calculating the first few elements:
ghci> let calcThing i = floor ((3 + sqrt 5) ^ i) ghci> map calcThing [0..5] [1,5,27,143,751,3935]
Assuming that the formula is:
item n = a * item n-1 + b * item n-2
We have:
27 = a * 5 + b * 1
143 = a * 27 + b * 5
We solve a set of linear equations and get:
item n = 4 * item n-1 + 7 * item n-2 (a = 4, b = 7)
We check:
ghci> let thing = 1 : 5 : zipWith (+) (map (* 4) (tail thing)) (map (* 7) thing) ghci> take 10 thing [1,5,27,143,761,4045,21507,114343,607921,3232085] ghci> map calcThing [0..9] [1,5,27,143,751,3935,20607,107903,564991,2958335]
Then we find that, unfortunately, this does not compute our function. But then we are pleased with the fact that he has the right to the correct number. Not understanding why, but encouraged by this fact, we are trying something like that. To find parameters for a modified formula:
thing n = a * thing n-1 + b * thing n-2 + c
Then we come to:
item n = 6 * item n-1 - 4 * item n-2 + 1
We check:
ghci> let thing = 1 : 5 : map (+1) (zipWith (+) (map (*6) (tail thing)) (map (* negate 4) thing)) ghci> take 16 thing == map calcThing [0..15] True