Introduction
Difference Rule Numbers
Sum Rule Numbers
Difference Rule in Other Bases
Sum Rule in Other Bases
A common investigation set to Key Stage 3 Mathematics classes involves writing down any 3-figure number (all digits different), reversing it and finding the difference between the two numbers. The question might then ask what all such answers have in common. Or it could be to find if the digits in the original number are ever recovered in the difference.
For a number of any length, the difference above is always divisible by 9. For 3-figure numbers, just one also obeys the rule that the difference contains all the original digits once, namely:
|
9 5 4 -
4 5 9 - - - 4 9 5 |
We will call this rule the Difference Rule. It happens, for this particular difference, that the digits are also in descending and ascending order in the original numbers. (No numbers with length less than 3 satisfy the rule at all). These conclusions can all readily be obtained by pupils, either by exhaustion or by algebra.
As a resource for the teacher intending to use this kind of investigation, a more detailed analysis of the Difference Rule numbers, and the similar Sum Rule numbers, is presented here. Some of the conclusions below may also be of more general interest to mathematicians.
It is possible that some of the results here are already published in the literature, though I have not seen any. If so, I willingly acknowledge this.
Introduction
Difference Rule Numbers
Sum Rule Numbers
Difference Rule in Other Bases
Sum Rule in Other Bases
Difference Rule numbers obey the following rule: if you write the number down, then write it down backwards and subtract the two numbers, the difference contains just the digits in the original number. The numbers all contain each digit only once.
Consider the problem of finding all such 4-figure numbers. Given the unique digits, A, B, C, D, you must find the digits so that the difference:
where A B C D, D C B A and W X Y Z are all 4-figure numbers (no leading zeros) and the digits W, X, Y, Z are the digits A, B, C, D arranged in some unspecified order.
For example, Computer Weekly, July 28th 1998, gave one such length 4 solution as:
| 7 6 4 1 -
1 4 6 7 - - - - 6 1 7 4 |
in which unique case the digits in the numbers are in descending and ascending order, respectively. Because of its very special properties, the answer here is a well-kown number, attributed to the Indian mathematician Shri Dattathreya Ramachandra Kaprekar.
We stay with the wider problem of all such 4-figure numbers. It can be proved that there only exists the following 3 additional solutions:
| 5 8 2 3 -
3 2 8 5 - - - - 2 5 3 8 |
2 9 6 1 -
1 6 9 2 - - - - 1 2 6 9 |
9 1 0 8 -
8 0 1 9 - - - - 1 0 8 9 |
It is interesting to note that the second of these 3 differences is half the first. And that by adding, instead of subtracting, in the first, we get the number in the last. We also get the last number by adding in the numerically ordered solution. If we add in the second of the three we get a new number, but if we test that for the Difference Rule we again get the answer in the last. The latter answer is another well-known number, obtained by first subtracting and then adding with any 3 digit number. It is also easily established as the resut of operating here, in the reverse order, on a 4 digit number, provided B + C > 9 and A + D < 9.
If we consider numbers of length 5, there are just 8 numbers with the Difference Rule property, as given here. It is easy to show that none of them can have 0 in the central position (they actually have 2, 6, 7 or 9 there).
| 7 6 9 4 1 -
1 4 9 6 7 - - - - - 6 1 9 7 4 |
5 8 9 2 3 -
3 2 9 8 5 - - - - - 2 5 9 3 8 |
9 6 7 3 2 -
2 3 7 6 9 - - - - - 7 2 9 6 3 |
6 0 2 7 3 -
3 7 2 0 6 - - - - - 2 3 0 6 7 |
| 8 9 6 0 4 -
4 0 6 9 8 - - - - - 4 8 9 0 6 |
7 0 2 5 4 -
4 5 2 0 7 - - - - - 2 5 0 4 7 |
6 9 7 2 3 -
3 2 7 9 6 - - - - - 3 6 9 2 7 |
6 0 7 3 2 -
2 3 7 0 6 - - - - - 3 7 0 2 6 |
Notice that some of these are trivial extensions of length 4 solutions, obtained by inserting 9 in the central position, whilst others are permutations of each other.
Now here are a few solutions easily obtainable for length 6. We can see again some extensions from 4-figure solutions, to this length:
| 7 9 6 4 0 1 -
1 0 4 6 9 7 - - - - - - 6 9 1 7 0 4 |
5 9 8 2 0 3 -
3 0 2 8 9 5 - - - - - - 2 9 5 3 0 8 |
9 6 1 0 3 8 -
8 3 0 1 6 9 - - - - - - 1 3 0 8 6 9 |
8 1 4 2 7 5 -
5 7 2 4 1 8 - - - - - - 2 4 1 8 5 7 |
These (and others) can be found computationally, quite quickly. There are, actually, 56 solutions of length 6.
Next, an example of some for order 7 might be:
| 8 1 4 9 2 7 5 -
5 7 2 9 4 1 8 - - - - - - 2 4 1 9 8 5 7 |
7 0 2 5 4 8 1 -
1 8 4 5 2 0 7 - - - - - - - 5 1 8 0 2 7 4 |
9 2 7 4 5 8 1 -
1 8 5 4 7 2 9 - - - - - - - 7 4 1 9 8 5 2 |
and there are 178 such solutions.
Here are one or two for order 8. The complete set is still solvable computationally in a reasonable time, though it does demand some effort. There are 645 solutions for this length:
| 8 7 5 6 3 4 2 1 -
1 2 4 3 6 5 7 8 - - - - - - - - 7 5 1 2 6 8 4 3 |
9 8 6 0 1 3 7 2 -
2 7 3 1 0 6 8 9 - - - - - - - - 7 1 2 9 0 6 8 3 |
9 7 2 5 0 3 4 6 -
6 4 3 0 5 2 7 9 - - - - - - - 3 2 9 4 5 0 6 7 |
Paradoxically, as the problem gets computationally more difficult, solutions become easier to find by eye and intuition, especially as there is a rapidly increasing number of them. For length 9 there is the degenerate solution below, and a total of 2204 solutions altogether.
| 9 8 7 6 5 4 3 2 1 -
1 2 3 4 5 6 7 8 9 - - - - - - - - 8 6 4 1 9 7 5 3 2 |
Note that this one is in descending and ascending order again. Clearly it is the only one of this order to be so. Here are some of the many others (illustrating trivial extensions again), as an example:
| 8 5 0 2 1 4 6 7 3 -
3 7 6 4 1 2 0 5 8 - - - - - - - - - 4 7 3 8 0 2 6 1 5 |
7 0 3 2 5 4 6 8 1 -
1 8 6 4 5 2 3 0 7 - - - - - - - - - 5 1 6 8 0 2 3 7 4 |
8 7 5 6 9 3 4 2 1 -
1 2 4 3 9 6 5 7 8 - - - - - - - - - 7 5 1 2 9 6 8 4 3 |
Finally there is a nearly degenerate length 10 solution shown below, and a great many others. Here it becomes impractical computationally to solve for more than a sample of the solutions. There are a couple more below:
| 5 6 7 8 9 0 1 2 3 4 -
4 3 2 1 0 9 8 7 6 5 - - - - - - - - - - 1 3 5 7 8 0 2 4 6 9 |
8 9 7 5 6 3 4 2 0 1 -
1 0 2 4 3 6 5 9 8 7 - - - - - - - - - - 7 9 5 1 2 6 8 4 0 3 |
| 2 7 4 3 6 9 8 5 0 1 -
1 0 5 8 9 6 3 4 7 2 - - - - - - - - - - 1 6 8 4 7 3 5 0 2 9 |
2 3 4 8 7 6 5 9 0 1 -
1 0 9 5 6 7 8 4 3 2 - - - - - - - - - - 1 2 5 3 0 8 7 4 6 9 |
Evidently, no solutions of length 10 can be in descending order. In fact, the only other solution in descending and ascending order, of any length apart from the one of length 4, is the degenerate length 9 number shown above.
It is interesting that the number of solutions (and the solution density) increases (decreases) exponentially with the number length (rather than, say, factorially, as might be conjectured). From the table below:
| Length of Number | Number of Solutions |
| 3 | 1 |
| 4 | 4 |
| 5 | 8 |
| 6 | 56 |
| 7 | 178 |
| 8 | 645 |
| 9 | 2204 |
it can be estimated that the growth factor for the density of solutions is approximately 0.363 (which is equivalent to 10 factorial / 10 to the power 7). The graph below presents the growth in number of solutions as a log-linear relationship.

Extrapolating from this data suggests there might be around 8000 Difference Rule solutions for number length 10.
Introduction
Difference Rule Numbers
Sum Rule Numbers
Difference Rule in Other Bases
Sum Rule in Other Bases
We can also look for numbers that obey the related Sum Rule, which for a 5-figure number is:
where V, W, X, Y, Z are the digits A, B, C, D, E in some undefined order.
Note that, consistent with the Difference Rule, we do not regard the reverse of a number as a separate solution.
It can be proven that there are no such numbers of length less than 5. There are, generally, fewer numbers of this nature than Difference Rule numbers.
It is also easy to see that there are no Sum Rule numbers in descending and ascending order.
Additionally, it can quite readily be demonstrated that Sum Rule numbers of length 5 must have either 5, 7 or 8 in the central position. Here are the only 6 such numbers of length 5:
| 4 5 7 8 3 +
3 8 7 5 4 - - - - - 8 4 5 3 7 |
6 7 5 8 1 +
1 8 5 7 6 - - - - - 8 6 1 7 5 |
7 9 8 2 1 +
1 2 8 9 7 - - - - - 9 2 7 1 8 |
| 4 8 7 5 3 +
3 5 7 8 4 - - - - - 8 4 5 3 7 |
6 8 5 7 1 +
1 7 5 8 6 - - - - - 8 6 1 5 7 |
7 2 8 9 1 +
1 9 8 2 7 - - - - - 9 2 7 1 8 |
Notice the property of the Sum Rule numbers that permits symmetrically placed digits to be interchanged. This holds for all lengths and means there is always an even number of these solutions. We may refer to them as different inversions.
It can, furthermore, be shown, surprisingly perhaps, that there are no solutions of length 6.
Of length 7 there are just 16, all variations of the following four, two of which are directly obtainable by a trivial extension from length 5 solutions above. The other two are again permutations of each other.
| 4 0 5 7 8 9 3 +
3 9 8 7 5 0 4 - - - - - - - 8 0 4 5 3 9 7 |
6 0 7 5 8 9 1 +
1 9 8 5 7 0 6 - - - - - - - 8 0 6 1 5 9 7 |
| 6 3 7 1 9 8 2 +
2 8 9 1 7 3 6 - - - - - - - 9 2 6 3 7 1 8 |
6 7 3 1 8 9 2 +
2 9 8 1 3 7 6 - - - - - - - 9 7 1 3 2 6 8 |
They are all characterised by having the central digit as either 1, 5 or 7.
For order 8 there are sums such as the following (and their trivial variations):
| 7 9 8 6 0 2 3 1 +
1 3 2 0 6 8 9 7 - - - - - - - - 9 3 0 6 7 1 2 8 |
2 7 5 3 4 6 8 1 +
1 8 6 4 3 5 7 2 - - - - - - - - 4 6 1 7 8 2 5 3 |
| 7 3 8 6 0 2 9 1 +
1 9 2 0 6 8 3 7 - - - - - - - - 9 3 0 6 7 1 2 8 |
2 5 7 3 4 8 6 1 +
1 6 8 4 3 7 5 2 - - - - - - - - 4 2 5 7 8 6 1 3 |
In fact, there are 112 Sum Rule solutions for length 8.
One can make a trivial extension from some length 8 solutions, to order 9. One example, extending the above, is:
| 2 5 7 3 0 4 8 6 1 +
1 6 8 4 0 3 7 5 2 - - - - - - - - - 4 2 5 7 0 8 6 1 3 |
And it is again still possible to compute all the order 9 solutions in a reasonable time, some more of which are given below:
| 3 5 8 6 4 0 2 7 1 +
1 7 2 0 4 6 8 5 3 - - - - - - - - - 5 3 0 6 8 7 1 2 4 |
3 5 8 0 4 6 2 7 1 +
1 7 2 6 4 0 8 5 3 - - - - - - - - - 5 3 0 6 8 7 1 2 4 |
In total there are 208 such solutions.
And finally, at length 10, there are many solutions (again with variations), such as these based on different trivial extensions from one of length 8:
| 2 9 5 7 3 4 8 6 0 1 +
1 0 6 8 4 3 7 5 9 2 - - - - - - - - - - 4 0 2 5 7 8 6 1 9 3 |
2 5 7 9 3 4 0 8 6 1 +
1 6 8 0 4 3 9 7 5 2 - - - - - - - - - - 4 2 5 9 7 8 0 6 1 3 |
| 2 9 5 8 3 4 7 6 0 1 +
1 0 6 7 4 3 8 5 9 2 - - - - - - - - - - 4 0 2 5 7 8 6 1 9 3 |
1 5 7 9 3 4 0 8 6 2 +
2 6 8 0 4 3 9 7 5 1 - - - - - - - - - - 4 2 5 9 7 8 0 6 1 3 |
At this length it is again not practical to compute all the solutions. And, unlike the Difference Rule numbers, it is also difficult to estimate how many length 10 Sum Rule solutions there are. It seems likely though, from the above, to be substantially less than 1000. Because of the symmetrical digits property, it must be a multiple of 16.
Introduction
Difference Rule Numbers
Sum Rule Numbers
Difference Rule in Other Bases
Sum Rule in Other Bases
The discussion above has considered all Difference Rule situations when working with decimal numbers. We can extend the idea, however, to think about Difference Rule numbers in other bases. There may be many such numbers, requiring computational solution. We can, however, say something about them directly.
Plainly, if we insist on no leading zeros, there are no solutions in binary arithmetic.
It is evident, however, that solutions in descending and ascending order, analogous to those in base 10, exist in all even bases greater than binary. In octal, base 8, for example, there is the analogous length 3 solution
| 7 4 3 -
3 4 7 - - - 3 7 4 |
and the length 7 analogous degenerate solution:
| 7 6 5 4 3 2 1 -
1 2 3 4 5 6 7 - - - - - - - 6 4 1 7 5 3 2 |
In base 4 the two analogous solutions coalesce, namely to:
| 3 2 1 -
1 2 3 - - - 1 3 2 |
As a further example, in hexadecimal, there are the two analogous solutions shown below:
| F 8 7 -
7 8 F - - - 7 F 8 |
| F E D C B A 9 8 7 6 5 4
3 2 1 -
1 2 3 4 5 6 7 8 9 A B C D E F - - - - - - - - - - - - - - - - E C A 8 6 4 1 F D B 9 7 5 3 2 |
It is further clear that there are no Difference Rule solutions in base 3.
There is also no degenerate solution for any odd bases. In odd bases not in the sequence 5, 11, 17, 23, ..., there is no order 3 solution either.
There is an order 3 solution for all bases in the sequence 5, 8, 11, 14, 17, ... . These are not, however, in descending and ascending order, they have their highest digit in the central position. The simplest example is for base 5:
| 3 4 1 -
1 4 3 - - - 1 4 3 |
Notice, in all these cases, the answer is the reverse of the original number.
For base 8, the solution is:
| 5 7 2 -
2 7 5 - - - 2 7 5 |
and in base 17, for example, there is (extending the digits to G = 16)
| B G 5 -
5 G B - - - 5 G B |
For indefinitely higher bases still, within this sequence, the other digits in the solution follow the pattern evident in the three cases above (i.e. 3, 5, 7, ..... and 1, 2, 3, .....).
There are actually no other length 3 Difference Rule solutions in any base up to base 10.
Interestingly, two islands of length 4 solutions exist, analogous to two of the base 10 solutions. In base 4 there are the two permutations:
| 3 1 0 2 -
2 0 1 3 - - - - 1 0 2 3 |
2 3 0 1 -
1 0 3 2 - - - - 1 2 0 3 |
And in base 5 there is the single length 4 solution analogous to the first above:
| 4 1 0 3 -
3 0 1 4 - - - - 1 0 3 4 |
An analogous solution to this then occurs in every higher base, including base 10 (i.e. 9108) and base 16 (F10E), and indefinitely further on, following the same pattern of changing digits (3, 4, 5, 6, ..... and 2, 3, 4, 5. ....).
A cluster of solutions corresponding to the second solution in base 4 above starts at base 7 with:
| 2 6 3 1 -
1 3 6 2 - - - - 1 2 3 6 |
and again continues indefinitely through every higher base, e.g. 2741 in base 8, 2961 in base 10 and 2FC1 in hexadecimal. The varying digits obey the pattern 6, 7, 8, 9, .... and 3, 4, 5, 6, .... .
Furthermore, it can be shown computationally, that the only other 4-figure solutions below base 9 are in base 6, which additionally has the two permutations:
| 4 3 1 2 -
2 1 3 4 - - - - 2 1 3 4 |
3 4 2 1 -
1 2 4 3 - - - - 2 1 3 4 |
Length 4 Difference Rule solutions are therefore generally rather sparse until base 9, which turns out, by computation, to have just 8, including the additional solutions below.
| 7 3 5 1 -
1 5 3 7 - - - - 5 7 1 3 |
6 5 2 3 -
3 2 5 6 - - - - 3 2 5 6 |
4 7 3 2 -
2 3 7 4 - - - - 2 3 4 7 |
| 5 1 7 3 -
3 7 1 5 - - - - 1 3 5 7 |
5 6 3 2 -
2 3 6 5 - - - - 3 2 5 6 |
5 6 4 1 -
1 4 6 5 - - - - 4 1 6 5 |
In base 5 there are no further (i.e. length 5) Difference Rule numbers.
The table below shows the number of length 5 or greater solutions for higher bases, up to base 10. The numbers for base 10 are repeated here for completeness.
| Base\Length | 5 | 6 | 7 | 8 | 9 |
|
6 |
9 | 26 | - | - | - |
| 7 |
5 | 16 | 0 | - | - |
| 8 | 5 | 50 | 115 | 330 | - |
| 9 | 16 | 32 | 96 | 235 | 0 |
| 10 | 8 | 56 | 178 | 645 | 2204 |
One solution here is worthy of particular note, namely the length 5 number in the base 9, below:
| 8 6 5 3 2 -
2 3 5 6 8 - - - - - 6 2 8 5 3 |
which is a Difference Rule number in an odd base, in descending and ascending order.
The table raises the possibility that there may be no Difference Rule solutions of maximum length in odd bases. Generally, it seems, there tends to be more solutions in even bases than in odd ones.
Introduction
Difference Rule Numbers
Sum Rule Numbers
Difference Rule in Other Bases
Sum Rule in Other Bases
We can, similarly, say something directly about Sum Rule numbers in other bases. Recall that Sum Rule numbers occur in pairs (actually powers of 2) of inversions, since symmetrically placed digits may be interchanged.
As with the Difference Rule, there can be no Sum Rule solutions in base 2.
In bases less than 11 at least, there are no length 3 solutions either.
There are analogous length 4 solutions as follows, only in bases in the sequence 6, 9, 12, .... The base 6 analogue is:
| 2 3 4 1 +
1 4 3 2 - - - - 4 2 1 3 |
and its base 9 counterpart:
| 3 5 6 2 +
2 6 5 3 - - - - 6 3 2 5 |
Subsequent numbers follow the same pattern, the digits increasing by 1, 2, 2 and 1 respectively, in successive bases in the sequence, and continuing indefinitely.
For length 5, there is an indefinitely long line of solutions analogous to the number 72891 in decimal. It starts at base 6 with
| 3 2 4 5 1 +
1 5 4 2 3 - - - - - 5 2 3 1 4 |
the digits increasing here by 1, 0, 1, 1, and 0 respectively, with each increase of 1 in the base. As another example, in base 11 there is:
| 8 2 9 A 1 +
1 A 9 2 8 - - - - - A 2 8 1 9 |
There are also length 5 solutions for the sequence of bases 6, 9, 12, ...., obtained by nearly trivial extension from the length 4 sequence above. Notice that the inserted central digit here is the highest in the base. Starting at base 6 then we have:
| 2 3 5 4 1 +
1 4 5 3 2 - - - - - 4 2 5 1 3 |
For this particular case only, the number is a permutation of the base 6 analogue above.
In base 9 the corresponding number is therefore:
| 3 5 8 6 2 +
2 6 8 5 3 - - - - - 6 3 8 2 5 |
and in base 12 it is:
| 4 7 B 8 3 +
3 8 B 7 4 - - - - - 8 4 B 3 7 |
and so on.
There is only one other length 5 Sum Rule number in a base less than 10. This is the additional base 9 solution below, which can be found computationally as:
| 4 6 5 7 2 +
2 7 5 6 4 - - - - - 7 5 2 4 6 |
Finally, the following table presents the number of solutions of length 6 or above, which may be found computationally, for the remaining bases less than 10. The results for base 10 are also included for comparison.
| Base\Length | 6 | 7 | 8 | 9 |
|
6 |
4 | - | - | - |
| 7 | 0 | 0 | - | - |
| 8 | 0 | 32 | 16 | - |
| 9 | 4 | 12 | 32 | 0 |
| 10 | 0 | 16 | 112 | 208 |
Given their symmetry property (yeilding 4 inversions in lengths 6 and 7, and 8 inversions in lengths 8 and 9) the occurrence of Sum Rule solutions, in all bases, is seen to be actually quite rare until, say, base 10 and length 8. As with Difference Rule numbers, it may also be that there are no Sum Rule numbers of maximum length in odd bases.
Introduction
Difference Rule Numbers
Sum Rule Numbers
Difference Rule in Other Bases
Sum Rule in Other Bases
Gordon Thackray January - December 2002