Hi again, I was researching a similar sequence, the padovan sequence which is like the fibonacci, but P[n] = P[n-2] + P[n-3]. In that code I keep only the last four terms of a list turned into a deque with the following code:
Hi,
That is also a very nice implementation if you don't want to keep a list of the whole sequence. Going forward in the discussion, we can actually avoid using deque and increase the speed almost by two.
Hi again, I was researching a similar sequence, the padovan sequence which is like the fibonacci, but
P[n] = P[n-2] + P[n-3]
. In that code I keep only the last four terms of a list turned into a deque with the following code:Similar could be done to save memory in Fibonacci.
Hi,
That is also a very nice implementation if you don't want to keep a list of the whole sequence. Going forward in the discussion, we can actually avoid using
deque
and increase the speed almost by two.