-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecaman.py
More file actions
30 lines (28 loc) · 779 Bytes
/
recaman.py
File metadata and controls
30 lines (28 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import sys
""" Recamán sequence with limit :P """
def seqtest(limit: int) -> list[int]:
""" Generate the sequence up to a non-negative integer limit. """
limit = int(abs(limit))
x = 0
xt = 1
seqlist = [0]
while True:
if((x - xt)>0 and (x - xt) not in seqlist):
x -= xt
else:
x += xt
if x > limit:
break
xt += 1
seqlist.append(x)
return seqlist
if __name__ == "__main__":
if len(sys.argv) > 1:
try:
limit = int(sys.argv[1])
except ValueError:
print("Please provide an integer limit, e.g.: python recaman.py 10000")
sys.exit(1)
print(seqtest(limit))
else:
print("Usage: python recaman.py <limit>")