1def recaman(n):
2 if not isinstance(n, int):
3 raise TypeError("%r is not an integer" %n)
4 elif n < 0:
5 raise ValueError("%d is negative" %n)
6 elif n == 0:
7 return 0
8 else:
9 lst = [recaman(k) for k in range(n)]
10 if (recaman(n-1)-n < 0) or (recaman(n-1)-n in lst):
11 return recaman(n-1)+n
12 else:
13 return recaman(n-1)-n
14
15for i in range(1, 11):
16 print(recaman(i))
1
2def recaman(n):
3 if not isinstance(n, int):
4 raise TypeError("%r is not an integer" %n)
5 elif n < 0:
6 raise ValueError("%d is negative" %n)
7 elif n == 0:
8 return 0
9 else:
10 lst = [recaman(k) for k in range(n)]
11 if (recaman(n-1)-n < 0) or (recaman(n-1)-n in lst):
12 return recaman(n-1)+n
13 else:
14 return recaman(n-1)-n
15
16for i in range(1, 11):
17 print(recaman(i))