DEV Community

Cover image for Largest palindrome product - Project Euler Solution
Deepak Raj
Deepak Raj

Posted on • Edited on • Originally published at codeperfectplus.com

5 3

Largest palindrome product - Project Euler Solution

Largest palindrome product - Project Euler Solution

Topic: Largest palindrome product

Problem Statement:

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.

You can find the original question here -> Project Euler

Largest palindrome product - Project Euler Solution

def largestPalindrome(bot, top):
    z = 0
    for i in range(top, bot, -1):
        for j in range(top, bot, -1):
            if isPalindrome(i*j):                
                if i * j > z:
                    z = i * j
    return z

def isPalindrome(num):
    return str(num) == str(num)[::-1]

print(largestPalindrome(100,999))
Enter fullscreen mode Exit fullscreen mode

Share Your Solutions for the Largest palindrome product

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay