-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path055.py
More file actions
37 lines (28 loc) · 763 Bytes
/
055.py
File metadata and controls
37 lines (28 loc) · 763 Bytes
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
def is_palindrome(n):
return str(n) == str(n)[::-1]
def reverse_and_add(number):
reverse = int(str(number)[::-1])
return reverse + number
def count(limit):
d = {0: 1}
for i in range(1, limit + 1):
if is_palindrome(i):
if i in d:
d[i] += 1
else:
d[i] = 1
continue
else:
r = i
for j in range(60):
r = reverse_and_add(r)
if is_palindrome(r):
if r in d:
d[r] += 1
else:
d[r] = 1
break
return d
N = int(input())
counts = count(N)
print(max(counts, key=counts.get), max(counts.values()))