Which five-digit number has the $n$th digit representing how many occurrences of the digit $(n-1)$ there are in the number, for all $n\le5$?
For example, the fourth digit represents the number of 3s, and the first digit represents the number of 0s.
Which five-digit number has the $n$th digit representing how many occurrences of the digit $(n-1)$ there are in the number, for all $n\le5$?
For example, the fourth digit represents the number of 3s, and the first digit represents the number of 0s.
The solution is
21200
This can be found by simply iterating from a starting point. Let's choose 40000 as a start (it's as good as any).
40000 — start with four zeroes (and count them)
40001 — count four zeroes, one four
31001 — count three zeroes, one one, one four
22010 — count two zeroes, two ones, one three
21200 — count two zeroes, one one, two twos
21200 — count two zeroes, one one, two twos
The next row counts the numbers it sees in the previous row. Once we hit two identical numbers back-to-back, we have settled on a solution.
You'll see that 43210, 11111, 22222, 33333, and 44444 are not issues if you make one simple admission.
43210
11111
05000
400001 — allow counting the 5, but don't permanently extend the length
41000
31001
22010
21200
21200
cjm shows in his answer that there is only one correct solution by using a Perl program to brute force the puzzle.
This can also be demonstrated logically:
First digit:
Second digit:
Third digit:
Fourth and fifth digits:
Therefore the number is 21200.
One answer is:
21200
There is :
2 zeroes, 1 one, 2 twos, 0 three, 0 four
The other answers give a correct solution, but they don't indicate whether it is the only solution.
In fact, 21200 is the only solution.
This is shown by this brute-force Perl solution:
for (10000 .. 44444) {
say $_ if substr($_, 0, 1) == tr/0//
and substr($_, 1, 1) == tr/1//
and substr($_, 2, 1) == tr/2//
and substr($_, 3, 1) == tr/3//
and substr($_, 4, 1) == tr/4//;
}
There are no solutions for 1,2 and 3 digits.
There are two solutions for 4 digits:
1210 and 2020
There is one for 5 digits:
21200
One for 7 digits:
3211000
Is there any other possible solution?
https://en.wikipedia.org/wiki/Self-descriptive_number
https://oeis.org/A138480
And the general math solution (or attempt to build one):
Since the first digit counts the number of 0s and the 2nd digit the number of 1s etc and since the total number digits is 5 the sum of all the digits must be 5. As a counter example if you take a number like 11112 this would imply there are a total of 6 digits which isn't possible. So we need five digits adding up to 5. Possible combinations are:- 11111, 01112, 00122, 00113, 00023 and 00014. If we encode these 6 possibilities according to the rule we get:- 11111 -> 05000 (no zeros, 5 ones, no 2s, 3s or 4s); 01112 -> 13100; 00122 -> 21200; 00113 -> 22100; 00023 -> 30110; 00014 -> 31001; Only one of these is a rearrangement namely 00122 which goes to 21200 which would map onto itself under the rule and so is the solution.