Skip to content

Instantly share code, notes, and snippets.

@johana-star
Created May 26, 2011 08:16
Show Gist options
  • Save johana-star/992758 to your computer and use it in GitHub Desktop.
Save johana-star/992758 to your computer and use it in GitHub Desktop.
Euler Project Problem #004
# Solution to Project Euler's fourth problem
# http://projecteuler.net/index.php?section=problems&id=4
# Find the largest palindromic number which is the product of two three-digit numbers.
def generate_and_test
numbers = []
999.downto(100) do |x|
999.downto(100) do |y|
number = x * y
if number.to_s == number.to_s.reverse then
numbers.push number
end
end
end
puts numbers.sort.last
p numbers.sort
end
generate_and_test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment