Created
December 12, 2012 08:24
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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