I’m NOT asking for a solution to this riddle.
So, I’m working through the Project Euler problems using Ruby.
I made a palindrome checker with the following method:
def is_palindrome(n)
if n.to_s == n.to_s.reverse
true
else
false
end
end
Using this, I use the next method to try and find the largest palindrome made with two 3 digit numbers.
x = 999
y = 998
while y > 100
if is_palindrome(x * y) == true
puts (x * y)
else
x-=1
y-=1
end
end
The result is the terminal throws a complete fit and gets stuck on 289982 and has to be Ctrl+C’d for it to stop.
As I said, I’m not looking for a solution to this riddle, but I want to know what it is my code is doing for this to happen. I’m still learning so my code is likely to be rather ugly, so extra karma points to anyone that can help me out with this.
In case a palindrome is found, you don’t decrement your variables. Since the variables remain the same, the same palindrome is found again. And so it goes…