diff options
Diffstat (limited to 'challenge-168/lubos-kolouch/python/ch-1.py')
| -rw-r--r-- | challenge-168/lubos-kolouch/python/ch-1.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/challenge-168/lubos-kolouch/python/ch-1.py b/challenge-168/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..8c8790c5dc --- /dev/null +++ b/challenge-168/lubos-kolouch/python/ch-1.py @@ -0,0 +1,39 @@ +""" Challenge 168 Task 1 LK Python """ + +from sympy import isprime + + +def generate_perrin_primes(n: int) -> list: + """ + Generate all primes up to n using the Perrin sequence. + """ + perrin_sequence = [3, 0, 2] + + perrin_primes: dict = {} + + while len(perrin_primes.keys()) < n: + + next_number = perrin_sequence[-3] + perrin_sequence[-2] + perrin_sequence.append(next_number) + + if isprime(next_number): + perrin_primes[next_number] = True + + return sorted(perrin_primes.keys()) + + +assert generate_perrin_primes(13) == [ + 2, + 3, + 5, + 7, + 17, + 29, + 277, + 367, + 853, + 14197, + 43721, + 1442968193, + 792606555396977, +] |
