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.
BOOM:


p n =(show n==(reverse$show n)) 
r=[999,998..100]a=maximum$filter p[x*y|x<-r,y<-r]
83 characters.

2 comments:

  1. Ruby... 95 characters.

    z=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

    ReplyDelete
  2. 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