In: Computer Science
Design in pseudo code a multiple recursive version of Tetranacci calculators.
Tetranacci numbers are a more general version of Fibonacci numbers and start with four predetermined terms, each term afterwards being the sum of the preceding four terms. The first few Tetranacci numbers are: 0, 0, 0, 1, 1, 2, 4, 8, 15, 29, 56, 108, 208, 401, 773, 1490, …
Here is the answer...
CODE:
def tetranacci(n):
if(n==0 or n==1 or n==2): #for first three numbers return 0
return 0
elif(n==3): #return 1 for fourth number
return 1
else: #recursively calling to sum up the back three numbers
return
tetranacci(n-4)+tetranacci(n-3)+tetranacci(n-2)+tetranacci(n-1)
n = int(input("Enter how many numbers you want : ")) #read how
many numbers he want
i = 0 #start with 0
while(i < n-1): #to run through given numbers count
print(tetranacci(i),end=", ") #call tetrancci with that number and
print the return result
i +=1 #increment i by 1
print(tetranacci(n-1)) #print the last tetranacci number
CODE Snapshot:
Pseudo code:
-> Read how many numbers he want
-> loop over through given number
->call tetranacci function with the number
-> increment number.
->print the tetranacci number for last number
Recursive tetranacci function:
-> if number==0 or 1 or 2
-> return 0
->else
->sum up the recursive calls of previous four numbers.
if you have any doubts please COMMENT...
If you understand the answer please give THUMBS UP...