Skip to content

Instantly share code, notes, and snippets.

@nbrew
Created February 9, 2012 00:31
Show Gist options
  • Save nbrew/1775824 to your computer and use it in GitHub Desktop.
Save nbrew/1775824 to your computer and use it in GitHub Desktop.
Largest palindrome made from the product of two 3-digit numbers.
# http://projecteuler.net/problem=4
def palindrome? s
s.to_s == s.to_s.reverse
end
products = []
nums = (100..999).to_a
nums.each do |n|
nums.each do |x|
products << product if palindrome? n*x
end
end
puts "Largest: #{products.sort.last}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment