recaman sequence in python
def recaman(n):
if not isinstance(n, int):
raise TypeError("%r is not an integer" %n)
elif n < 0:
raise ValueError("%d is negative" %n)
elif n == 0:
return 0
else:
lst = [recaman(k) for k in range(n)]
if (recaman(n-1)-n < 0) or (recaman(n-1)-n in lst):
return recaman(n-1)+n
else:
return recaman(n-1)-n
for i in range(1, 11):
print(recaman(i))