a blog about engineering, programming, and deteriorating buildings on campus.
3.06.2011
Euler 004
Problem 004:
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 X 99.
Find the largest palindrome made from the product of two 3-digit numbers.
I just realized I'm an idiot. (Surprised it took this long?) Could have saved some characters by writing [100..999] instead of the reverse list because I am taking the maximum of the result anyway. CRAP.
Ruby... 95 characters.
ReplyDeletez=0
(100..999).each{|x|(x..999).each{|y|x*y>z ?(x*y).to_s==(x*y).to_s.reverse ? z=x*y:0:0}}
p z
I just realized I'm an idiot. (Surprised it took this long?) Could have saved some characters by writing [100..999] instead of the reverse list because I am taking the maximum of the result anyway. CRAP.
ReplyDelete