0
How to make this code faster? It works, but not fast enough.
#!/bin/ruby
def isPalin(mul)
if mul.to_s == mul.to_s.reverse then
return true
else
return false
end
end
def lp(n)
arr = []
for a1 in (100..999)
for a2 in (100..999)
mul = a1*a2
break if mul > n
if mul <= n then
arr.push(mul) if isPalin(mul)
end
end
end
arr.sort!
puts arr[arr.length-1]
end
t = gets.strip.to_i
for a0 in (0..t-1)
n = gets.strip.to_i
lp(n)
end
Thanks for your help!
Please translate your question, this is the English OS.
– user28595
translated right below, Sorry!
– Henrique
Enrique, the field below is for answers only, the correct is you edit the question with the translation.
– user28595