Skip to content

Instantly share code, notes, and snippets.

@jjuliano
Created December 12, 2012 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjuliano/4266072 to your computer and use it in GitHub Desktop.
Save jjuliano/4266072 to your computer and use it in GitHub Desktop.
Find the largest palindrome made from the product of two 3-digit numbers
#!/usr/bin/env ruby
# 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 palin-
# drome made from the product of two 3-digit numbers.
# Solution:
palindromes = []
(100..999).each do |x|
(100..999).each do |y|
product = x * y
palindromes << product if product.to_s == product.to_s.reverse
end
end
palindromes.sort[-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment