$s(x)$ is $x$ with digits sorted in increasing order, e.g. $s(452) = 245, s(604270) = 2467$.
$$f(x) = x - s(x)$$
Does applying $f(x)$ repeatedly for any non-negative integer always reach a sorted-digit number? (after which the next step is $0$ as the sorted version of an already sorted number is itself and $x - x = 0$)
Is there a way to mathematically predict how many steps it will take before reaching 0?
Here is a python program that shows the steps before reaching 0:
def s(x):
return int("".join(sorted(list(str(x)))))
def f(x):
yield x
while x != 0:
x = x - s(x)
yield x
for step in f(int(input("> "))):
print(step)