Tetranacci numbers are defined by the following recurrence relation:
Lisa decides to write a quick python script to calculate the n th Tetranacci number:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
If she calls tetra(5), then the tetra() procedure will be called 9 times all together (if you include the initial invocation):
1 2 3 4 5 6 7 8 9 |
|
How many times will it be called for tetra(10)?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
On my first attempt I went along and found the sequence 5 , 9 , 1 7 , 3 3 , 6 5 and guessed that the general pattern was N n = 2 n − 2 + 1 , so N 1 0 = 2 5 7 , which is wrong. I then went back and did the actual calculations and found instead that N 9 = 1 2 5 and N 1 0 = 2 4 1 . Curious that it followed such a nice pattern from n = 4 to n = 8 and only then started to deviate.
Log in to reply
Whoa... Interesting that it followed such a common pattern so closely. I suspect that it has to do with the fact that these are Tetranacci numbers. If they were Petranacci or Hexanacci numbers, I suspect they may follow the 2 n + 1 pattern for a bit longer....
Problem Loading...
Note Loading...
Set Loading...
For the first few numbers it is easy to see that the number of times the procedure is invoked is as follows;
And, in fact, we know that, in general tetra(n) will call tetra(n-1), tetra(n-2), tetra(n-3), and tetra(n-4). So, the total number of calls it will make will be the sum of the four previous numbers of calls plus 1 (the call itself).
Or in general, the number of calls, N, will be given by:
Equations quite similar to the Tetranacci numbers themselves!
Using this recursion relation, we find that N 1 0 = 2 4 1 .