-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patheuler004.py
More file actions
50 lines (39 loc) · 1.26 KB
/
Copy patheuler004.py
File metadata and controls
50 lines (39 loc) · 1.26 KB
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
"""
A palindromic number reads the same both ways.
The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 * 99.
Find the largest palindrome made from the product of two 3-digit numbers.
"""
import math
def isPalindrome(number):
numString = str(number)
for i in range(len(numString) / 2):
if numString[i] == numString[len(numString) - 1 - i]:
continue
else:
return False
return True
def getPalindromes():
palindromes = set()
for i in range(100, 1000, 1):
for j in range(100, 1000, 1):
if isPalindrome(i * j):
palindromes.add(i * j)
return sorted(palindromes)
def main():
t = int(raw_input().strip())
sortedPalindromes = getPalindromes()
for _ in xrange(t):
n = int(raw_input().strip())
for p in sortedPalindromes:
if p < n and p != sortedPalindromes[-1]:
continue
elif p == sortedPalindromes[-1] and p != n:
print p
else:
print sortedPalindromes[sortedPalindromes.index(p) - 1]
break
if __name__ == '__main__':
# print "This program is being run by itself"
main()
else:
print 'I am being imported from another module'