-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_4.py
More file actions
30 lines (25 loc) · 788 Bytes
/
problem_4.py
File metadata and controls
30 lines (25 loc) · 788 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 10 08:00:20 2019
@author: lisestork
"""
#problem 4:
#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 numpy as np
import itertools
import time
def palindrome(digits):
a = np.arange(pow(10,digits-1),pow(10,digits),1,dtype=int)
p = list([x * y for x, y in itertools.product(a, a)])
for nr in sorted(p, reverse=True):
if(nr == reversed(nr)):
return nr
break
start = time.time()
x = palindrome(3)
end = time.time()
print("Script ran for {} seconds".format(end-start))
print("Answer: ", x)