Challenge description
Let's take a positive integer n
, reverse its digits to get rev(n)
and get the absolute value of the difference of these two numbers: |n - rev(n)|
(or abs(n - rev(n))
).
Example:
n = 5067
rev(n) = 7605
|n - rev(n)| = |5067 - 7605| = |-2538| = 2538
After repeating this operation sufficiently many times, most numbers will become 0
(thus terminating the loop)...
5067 -> 2538 -> 5814 -> 1629 -> 7632 -> 5265 -> 360 -> 297 -> 495 -> 99 -> 0
...though some numbers (like 1584
) get stuck in an infinite loop:
1584 -> 3267 -> 4356 -> 2178 -> 6534 -> 2178 -> 6534 -> 2178 -> 6534 -> ...
^ infinite loop starts here
Your job is to determine if a given integer gets stuck in an infinite loop.
Input description
A positive integer.
Output description
A truthy value (True
, 1
) if the number gets stuck in an infinite loop, a falsy value (False
, 0
) otherwise.