euler/euler004.rb

29 lines
447 B
Ruby
Raw Normal View History

2014-04-25 23:59:14 +00:00
def isPalindrome(n)
numString = n.to_s
for i in 0..(numString.length-1)/2
if !(numString[i] == numString[numString.length-1-i])
return false
end
end
return true
end
def productsOfThreeDigits
products = []
for i in 100..999
for j in 100..999
products << i*j
end
end
products
end
palindromes = []
for i in productsOfThreeDigits
if isPalindrome(i)
palindromes << i
end
end
puts palindromes.sort