Take a three digit number where the digit do not repeat (i.e., not 111, 112, 222 etc.)* [*I first said the digits couldn't be the same, but actually there should not be any repeated digits.], for example 374. Re-arrange the digits so that you have the highest and smallest numbers that can be made — 743 and 347. Subtract the smallest from the largest, giving 396. Now keep repeating. I.e. 963 - 369 gives 594 then 954 - 459 gives 495. Now you will always get 495. Try it on some more three digit numbers. Interesting?
Write a program to verify this result for all the three digit numbers
Now try it on some four digit numbers. Still interesting?
Use your program to verify the result for four digit numbers
If you do this again for five digits then something different will happen. Instead of finding a single result you will find three loops. At six digits there are two numbers and one loop. For all numbers up to 20 digits from here on there are different combinations of loops and constants.
See how many constants and loops you can find for ever increasing numbers of digits
So far this has all been in base 10, but we should be able to carry out the same exercise in any other base.
What happens if you repeat this exercise in base 16?