TheAlgorithms-Ruby/project_euler/problem_4/sol1.rb
2020-12-28 15:00:05 -08:00

11 lines
No EOL
389 B
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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.
answer = 0
999.downto(99) do |i|
999.downto(99) do |j|
t = (i * j)
answer = i * j if (t.to_s == t.to_s.reverse) && (t > answer) && (t > answer)
end
end
puts answer