In [1]:
def is_palindromic_number(x):
x = str(x)
return x == x[::-1]
In [2]:
is_palindromic_number(9009)
Out[2]:
In [3]:
is_palindromic_number(90109)
Out[3]:
In [4]:
is_palindromic_number(90019)
Out[4]:
In [5]:
highest_palindromic_number = 0
for i in range(100, 1000)[::-1]:
for j in range(100, 1000)[::-1]:
if j > i:
continue
k = i * j
if is_palindromic_number(k) and k > highest_palindromic_number:
# print i, j, k
highest_palindromic_number = k
print highest_palindromic_number
In [6]:
def find_highest_palindromic_number(a, b):
highest_palindromic_number = 0
for i in range(a, b)[::-1]:
for j in range(a, b)[::-1]:
if j > i:
continue
k = i * j
if is_palindromic_number(k) and k > highest_palindromic_number:
# print i, j, k
highest_palindromic_number = k
return highest_palindromic_number
In [7]:
find_highest_palindromic_number(100, 1000)
Out[7]:
In [8]:
%timeit find_highest_palindromic_number(100, 1000)
In [9]:
def find_highest_palindromic_number(a, b):
highest_palindromic_number = 0
for i in range(a, b)[::-1]:
for j in range(a, b)[::-1]:
if j > i:
continue
k = i * j
if k > highest_palindromic_number and is_palindromic_number(k):
# print i, j, k
highest_palindromic_number = k
return highest_palindromic_number
In [10]:
find_highest_palindromic_number(100, 1000)
Out[10]:
In [11]:
%timeit find_highest_palindromic_number(100, 1000)
In [ ]: