Skip to content

Instantly share code, notes, and snippets.

@abdollar
Created December 12, 2011 01:09
Show Gist options
  • Save abdollar/1463968 to your computer and use it in GitHub Desktop.
Save abdollar/1463968 to your computer and use it in GitHub Desktop.
Find the largest palindrome made from the product of two 3-digit numbers
def palindrome?(str); str.reverse == str; end
max = 0
900.upto(999) { |a|
a.upto(999) { |b|
max = [max, a * b].max if palindrome?((a * b).to_s)
}
}
max
array = (900..999).to_a
array.inject([0]) { |i,sum| i += array.map { |n| sum*n } }.select{|v| palindrome?(v.to_s)}.uniq.sort.last
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment