-
Notifications
You must be signed in to change notification settings - Fork 0
/
p4.py
36 lines (29 loc) · 783 Bytes
/
p4.py
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
# -*- coding: utf-8 -*-
"""
Created on Mon Mar 6 18:54:29 2017
@author: Refaia
"""
import math
import time
def isPalindrome(n) :
strInt = str(n)
if len(strInt) == 1 or len(strInt) == 0 :
return True
if strInt[0] == strInt[-1] :
return isPalindrome(strInt[1:-1])
else :
return False
def findLargestPalindrome() :
largestPalindrome = -math.inf
delta = time.time()
for i in range(999, 99, -1) :
for j in range(i, 99, -1) :
if isPalindrome(i * j) :
largestPalindrome = max(i * j, largestPalindrome)
delta = time.time() - delta
print(delta)
return largestPalindrome
def main() :
print(findLargestPalindrome())
if __name__ == "__main__" :
main()