koyoweblog log

2010/10/11 までの http://d.hatena.ne.jp/sasashin の記事をインポートしただけです。

Problem 4

http://projecteuler.net/index.php?section=problems&id=4

左右どちらから読んでも同じ値になる数を回文数という。
2桁の数の積で表される回文数のうち、最大のものは 9009 = 91 × 99 である。
では、3桁の数の積で表される回文数のうち最大のものはいくらになるか。

これもワンライナで。Ruby だと文字列操作が楽勝過ぎる。

p (100..999).inject([]){|r,i| r+(i..999).map{|j| i*j}.select{|ij| ij.to_s.reverse==ij.to_s}}.max