Largest palindrome product: Difference between revisions
m
cleanup
(Python example) |
m (cleanup) |
||
Line 693:
def largestPalindrome(n):
""" find largest palindrome that is a product of two n-digit numbers """
m, tail = 0, n // 2
head = n - tail
Line 712 ⟶ 709:
it = tails(tail)
if I!=J: it = double(it)
val = (I + t1)*(J + t2)
s = str(val)
if s == s[::-1] and val>m:
sol = (I + t1, J + t2)
m = val
if m:
print("{:2d}\t{:4d}".format(n, m % 1337), sol, sol[0] * sol[1])
return m % 1337
return 0
if __name__ == "__main__":
|