-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPE_Q4.py
More file actions
34 lines (28 loc) · 933 Bytes
/
PE_Q4.py
File metadata and controls
34 lines (28 loc) · 933 Bytes
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
"""
Question:
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.
"""
from math import floor
start_pal = 1000000
start_int = 999
stop_int = 100
def is_palindrome(test_int: int) -> bool:
int_list = list(str(test_int))
int_len = len(str(test_int))
for i in range(floor(int_len/2)):
if int_list[i] != int_list[int_len-i-1]:
return False
print("Found palindrome {}".format(test_int))
return True
def is_three_digit(test_int: int) -> bool:
if len(str(test_int)) == 3:
return True
for i in range(start_pal, 10000, -1):
if is_palindrome(i):
for j in range(start_int, stop_int, -1):
k = i / j
if k == round(k) and is_three_digit(round(k)):
print(j, k)
quit()