Solution for problem 4
This commit is contained in:
parent
da28ecdd09
commit
98006398d9
36
src/Python/Problem004.py
Normal file
36
src/Python/Problem004.py
Normal file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Created on 18 Mar 2017
|
||||
|
||||
@author: David Doblas Jiménez
|
||||
@email: daviddoji@pm.me
|
||||
|
||||
Solution for problem 4 of Project Euler
|
||||
https://projecteuler.net/problem=4
|
||||
"""
|
||||
|
||||
from utils import timeit
|
||||
|
||||
|
||||
@timeit("Problem 4")
|
||||
def compute():
|
||||
"""
|
||||
A palindromic number reads the same both ways. The largest palindrome made
|
||||
from the product of two 2-digit numbers is 9009 = 91 x 99.
|
||||
|
||||
Find the largest palindrome made from the product of two 3-digit numbers.
|
||||
"""
|
||||
ans = 0
|
||||
for i in range(100, 1000):
|
||||
for j in range(100, 1000):
|
||||
palindrome = i * j
|
||||
s = str(palindrome)
|
||||
if s == s[::-1] and palindrome > ans:
|
||||
ans = palindrome
|
||||
|
||||
return ans
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
print(f"Result for problem 4: {compute()}")
|
Loading…
x
Reference in New Issue
Block a user