35 lines
799 B
Python
35 lines
799 B
Python
|
|
import time
|
|
time.clock()
|
|
|
|
def is_sync(num):
|
|
s = str(num)
|
|
return s == s[::-1]
|
|
|
|
def is_lic(num, lic_set, non_set):
|
|
step = set([num])
|
|
for i in range(50):
|
|
num = num + int(str(num)[::-1])
|
|
step.add(num)
|
|
if num in lic_set:
|
|
return (True, step)
|
|
if num in non_set:
|
|
return (False, step)
|
|
if is_sync(num):
|
|
return (False, step)
|
|
return (True, step)
|
|
|
|
def search(limit):
|
|
lic_set = set()
|
|
non_set = set()
|
|
for x in range(1, limit + 1):
|
|
judge, step = is_lic(x, lic_set, non_set)
|
|
if judge:
|
|
lic_set |= set(filter(lambda x: x <= limit, step))
|
|
else:
|
|
non_set |= set(filter(lambda x: x <= limit, step))
|
|
return lic_set
|
|
|
|
print(len(search(10000)))
|
|
print(time.clock())
|