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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
""" Challenge 154 Task 2 LK """
from sympy import isprime
class PadovanPrimes:
def __init__(self):
self.nums_cache = [1, 1, 1]
self.seen_nums = {}
def gen_next_num(self):
"""Calculate the next Padovan num"""
self.nums_cache.append(self.nums_cache[-2] + self.nums_cache[-3])
def get_n_unique(self, what: int):
"""Get the n unique numbers"""
counter = 0
output = []
while counter < what:
self.gen_next_num()
if not isprime(self.nums_cache[-1]):
continue
if self.seen_nums.get(self.nums_cache[-1], -1) != -1:
continue
output.append(self.nums_cache[-1])
counter += 1
self.seen_nums[self.nums_cache[-1]] = 1
return output
def main():
"""Do the main thing"""
padovan = PadovanPrimes()
assert padovan.get_n_unique(10) == [
2,
3,
5,
7,
37,
151,
3329,
23833,
13091204281,
3093215881333057,
]
if __name__ == "__main__":
main()
|