aboutsummaryrefslogtreecommitdiff
path: root/challenge-156/lubos-kolouch/python/ch-1.py
blob: 66576b2f523c0f60c6197014256a6a9c0553ab00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
""" Challenge 156 Task 1 LK """
import re

from sympy import isprime


def get_pernicious(what: int) -> list:
    """Get the pernicious numbers"""

    nums: list[int] = []

    num = 0
    while len(nums) < what:
        num += 1
        bin_num = f"{num:b}"
        bin_num = re.sub("0", "", bin_num)
        if isprime(len(bin_num)):
            nums.append(num)
    return nums


assert get_pernicious(10) == [3, 5, 6, 7, 9, 10, 11, 12, 13, 14]