Skip to content

Instantly share code, notes, and snippets.

@evansneath
Created August 20, 2011 23:14
Show Gist options
  • Save evansneath/1159822 to your computer and use it in GitHub Desktop.
Save evansneath/1159822 to your computer and use it in GitHub Desktop.
Palindromes
def palindromes(min, max):
"""Finds the largest palindrome of the product of two numbers between an desired range.
Arguments:
min: Minimum value limit.
max: Maximum value limit.
Returns:
Largest palindrome of the product of two numbers between the established range.
"""
a, b, product, highest = min, min, 0, 0
while a < max:
while b < max:
product = a * b
# determine if the product is reversible
if str(product)[::-1] == str(product):
if product > highest:
highest = product
b = b + 1
a, b = a + 1, min
return highest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment