aboutsummaryrefslogtreecommitdiff
path: root/challenge-102/lubos-kolouch/python/ch-1.py
blob: 27093ae3fec72fd006c066716dee75036672668b (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
41
42
43
44
45
46
47
48
49
50
51
#!/bin/env python
"""
#===============================================================================
#
#         FILE: ch-1.py
#
#        USAGE: ./ch-1.py
#
#  DESCRIPTION: Perl Weekly Challenge #102
#               Task 1 - Rare Numbers
#
#       AUTHOR: Lubos Kolouch
#      CREATED: 03/06/2021 11:18:30 AM
#===============================================================================
"""
from math import sqrt


def get_rare_numbers(what: int):
    """ Get all rare number in the give range """

    pos = '1' + '0'*(what-1)

    output = []
    while 1:
        pos = str(int(pos)+1)

        if len(pos) > what:
            break

        rev_num = pos[::-1]

        if int(pos) - int(rev_num) <= 0:
            continue

        if sqrt(int(pos) - int(rev_num)) != int(sqrt(int(pos) - int(rev_num))):
            continue

        if sqrt(int(pos) + int(rev_num)) != int(sqrt(int(pos) + int(rev_num))):
            continue

        print(pos)

        output.append(int(pos))

    return output


assert get_rare_numbers(2) == [65]
assert get_rare_numbers(6) == [621770]
assert get_rare_numbers(9) == [281089082]