Skip to content

Instantly share code, notes, and snippets.

@iliakonnov
Last active January 21, 2017 16:24
Show Gist options
  • Save iliakonnov/e83b56a34dfcfb058415397081085a17 to your computer and use it in GitHub Desktop.
Save iliakonnov/e83b56a34dfcfb058415397081085a17 to your computer and use it in GitHub Desktop.
'''
https://projecteuler.net/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.
'''
from time import time
n = 0
start = time()
DELAY = 1000
for a in range(9, 0, -1):
for b in range(9, -1, -1):
for c in range(9, -1, -1):
eqRes = "{a}{b}{c}{c}{b}{a}".format(a=a,b=b,c=c)
for x in range(9, 0, -1):
for z in range(9, 0, -1):
for y in range(9, -1, -1):
for q in range(9, -1, -1):
eq = "{x}{y}*{z}{q}=={eqRes}".format(x=x,y=y,z=z,q=q,eqRes=eqRes)
res = eval(eq)
if n == DELAY or res:
print("{eq} is {res}\t{t:.20f}".format(eq=eq, res=res, (t=time()-start)/DELAY))
n = 0
start = time()
if res:
break
else:
n += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment