aboutsummaryrefslogtreecommitdiff
path: root/challenge-149/lubos-kolouch/python/ch-1.py
blob: 74fb3990bebd0fae3c41d37a103522bbea4ac725 (plain)
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
""" Challenge 149 Task 1"""
fibs = []
fib_hash = {}

fibs.append(0)
fibs.append(1)

fib_hash[0] = 1
fib_hash[1] = 1

def gen_more_fibs(limit:int):
    """ Generate more Fibonacci numbers if needed"""

    while fibs[-1] < limit:
        new_fib =fibs[-1] + fibs[-2]
        fibs.append(new_fib)
        fib_hash[new_fib] = 1


def get_numbers(what: int):
    """Get the list as required"""

    count = 0
    pos = 0

    output = []

    while count < what:
        gen_more_fibs(pos)
        try:
            fib_hash[sum(list(map(int, str(pos))))]
            output.append(pos)
            count += 1
        except KeyError:
            pass
        pos += 1

    return output

assert get_numbers(20) == [0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44]