Project Euler Problem 4 Solution

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.

My solution in Ruby:

var = 0
999.downto(100) { |i|
  999.downto(100) { |j|
    prod = i * j
    var = [var, prod].max if prod.to_s == prod.to_s.reverse
  }
}
puts "Maximum palindrome is #{var}."

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.