to site top page

Problem 36 - Project Euler

def rev(s)
    s.split(//).reverse.join
end

#start_time = Time::now

pal_sum = 0
for i in 1..999
    if i.to_s == rev(i.to_s)
        if i.to_s(2) == rev(i.to_s(2))
            pal_sum += i
        end
    end
    if i >= 10
        gen = (i.to_s + rev(i.to_s)).to_i
        if gen.to_s(2) == rev(gen.to_s(2))
            pal_sum += gen
        end
        if i < 100
            10.times {|x|
                gen5 = (i.to_s + x.to_s + rev(i.to_s)).to_i
                if gen5.to_s(2) == rev(gen5.to_s(2))
                    pal_sum += gen5
                end
            }
        end
    end
end
puts pal_sum

#end_time = Time::now
#puts end_time - start_time

can't load my result

最近の記事(5件分)

する事

そのうち記事にするかもリスト

欲しい本