re: Project Euler #4 - Largest Palindrome Product VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Here's my Python solution! def palindrome_number(): _range = xrange(100, 1000) palindrome = None for i in _range: for j in _...
 

How's the run time? I think yours is Python 2?

Here's mine in Python 3 :) It's a bit more complicated because I try to write them more flexible. Like how this problem shows 2 digit numbers as an example and 3 for the actual problem, so I wrote it to take the number of digits per number as an input

import time
def largestPalindromeProduct(digits):
  min, max, temp, pal = '1', '', 0, 0
  for _ in range (1,digits):
    min += '0'
  for _ in range (0,digits):
    max += '9'
  min = int(min)-1
  max = int(max)
  start = time.time()
  for num1 in range (max,min,-1):
    for num2 in range (num1,min,-1):
      temp = num1 * num2
      if temp < pal:
        break
      if str(temp) == "".join(reversed(str(temp))):
        pal = temp
  end = time.time()
  print(pal, end=' ')
  print(end-start)
code of conduct - report abuse