I am working with series like Fibonacci series... (In Fibonacci series the nth term is the sum of n-1 and n-2 only.) But in my case I want to nth term is the sum of half of the previous terms.. for example:
n=5
Output should be: [0, 1, 1, 2, 3]
n=12
Output should be: [0, 1, 1, 2, 3, 6, 11, 22, 42, 84, 165, 330]
def my_function(n):
list1=[0,1]
for i in range(0,n-2):
if(i>2):
value=sum(list1[i//2+1:])
else:
value=list1[i]+list1[i+1]
list1.append(value)
return list1
print(my_function(5))
I have done this without recursive function but I am thinking how to do it using recursively and memoization. Can you help me to solve this..