Digits

(Hard Problem No# 1)


If you take the number 6174, and arrange its digits to form the biggest and smallest numbers, and then subtract these two, you get the number 6174 back again. That is, 7641 - 1467 = 6174. Other four digit numbers whose digits are not all the same will form other numbers. However, if you apply this process multiple times to any of these numbers, you will eventually end up with the number 6174.

Transformations such as the one described above, when applied repeatedly in this manner, will eventually hit upon repeating sequences of numbers. In the case of the transformation described above applied to 4 digit numbers whose digits are not all the same, repeated application results in striking the single element sequence containing 6174. If we used 6 digit numbers, some starting numbers would result in the repeating sequence 840852, 860832, 862632, 642654, 420876, 851742, 750843, and other starting numbers would result in the single element sequence 631764.

Your task is to determine all sequences in 8 digit numbers whose digits are not all the same, when the transformation described above is applied repeatedly. Your output should consist of a line containing the number of sequences, followed by each sequence on a line. The sequences should be listed in ascending numerical order, with the ordering done on the smallest number in each sequence. Each sequence line should contain the smallest number in the sequence, and the length of each sequence including the first number.

There is no input required for this problem.


########################################################################## Competition Server comp@arcadia.cs.rmit.edu.au (via comp@cs.curtin.edu.au) Problems with server: contact Craig Dillon (cdillon@cs.curtin.edu.au) ##########################################################################