Files
contests/004/main.py

62 lines
846 B
Python

import os
import numpy
# Find the largest palindrome made from the product of two 3-digit numbers
def reverse(s):
return s[::-1]
def getPalins(n):
res = [0]
m = 1
while len(str(m)) <= n:
s = str(m)
if s == reverse(s):
res.append(m)
m = m + 1
return res
def checkPalin(n):
s = str(n)
return s == reverse(s)
def getProducts(lower, upper):
res = []
for i in range(lower, upper + 1):
for j in range(lower, upper + 1):
res.append(i*j)
return res
def main():
testtext = "Hello, this is Patrick"
print(testtext)
# palins = getPalins(6)
# print(palins)
prods = getProducts(100, 999)
palinprods = list(filter(lambda x: checkPalin(x), prods))
print(max(palinprods))
if __name__ == "__main__":
main()