-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem4.py
32 lines (27 loc) · 831 Bytes
/
problem4.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
"""
project euler problem 4
find the largest palindrome number made from the product of 2 three digit numbers
"""
def ispalindrome (n):
forward=n
reverse=0
while n > 0:
# if the last digit is zero this is not a palindrome number
if n % 10 == 0 and reverse == 0:
return False
# collect the digits in reverse order
reverse = reverse * 10;
reverse += n % 10
n = int(n/10);
if reverse == forward:
return True
else:
return False
highest_palindrome=1
# too lazy to count from 100 to 999 since 900 to 999 likely has some palindromes
for x in range(900,999):
for y in range(x,999):
product=x*y
if ispalindrome(product) and product > highest_palindrome:
highest_palindrome=product
print(highest_palindrome)