# Number Digits Puzzle #1 – Solution

A couple of days ago, I posted the following puzzle:

There is a ten digit number where the leftmost digit is also the number of zeros in  the number, the second leftmost digit is the number of ones and so forth until the last digit (or rightmost digit) is the number of nines in that number. What is this number and is it unique?

Congratulations to the folks that figured it out, including Trae (of TraeBlain.com)who posted the solution to the comments section.  I’d award him a prize if I had one to give.  Instead he’ll have to settle for a virtual pat on the back.

Now the real question is how do you come up with the answer and is it unique?  Additionally, you might ask how this works for a smaller number of digits, that is, do the same problem but start with only 3 digits, or 4 digits, etc.?

I came up with a very similar explanation as the original source for the problem so I’ll give credit where credit is due.  You can read the original post here: http://begghilos2.ath.cx/~jyseto/Academia/Math-Problem-1.php

As there are ten digits in the number, and the digits themselves
reflect the number of digits in the number, the sum of the digits in
the number must add up exactly to ten. Therefore, the largest number
that can exist in the last (ninth) digit is a one, because anything
more would mean that there are two nines in the number, which already
adds up to eighteen which is more than ten. This same argument can be
applied to every digit in the number to obtain the following maximum
values for each digit:

9953221111

These theoretical maxima can be reduced by taking into account
the digit as well as the digits that it represents. For example,
in the ones position (second digit), any number greater than four
is not possible. If a value of five or higher was used, then there
would be at least five ones in the number, without considering that
number itself, which means that the sum of the digits is already over
ten. This argument can be applied to most of the lower order digits
to reduce the maximum values for each digit:

9533211111

There are still practical limits to some of these values, and
one can reduce the range of values by taking into consideration the
positions of each of the digits that each number represents. For
example, if the third digit was a three, then that would mean that
there are three twos in the number. The lowest order positions that
these twos can take are the first (zeros), second (ones), and fourth
(threes) position.

2232______

This means that there are at least two more ones, and another three
in the number, which puts us over the ten limit. Using this argument
for the other digits, the practical maxima become:

9321111111

Now we can look at each position individually. Consider the last
digit in the number.

_________x

We know that this last digit must be a one or zero. If the number
was one, then there must be a nine in the number. The only possible
location is at the front (the zeros),

9________1

which would mean that there are nine zeros. As there are only
eight spots left in the number, this is impossible. Therefore, the
last digit is a zero. Continuing onto the eight’s digit,

________x0

we know that there are only two possible values it can take. If
this number was one, then the only possible location for the eight is
in the first spot, which would suggest that there are eight zeros. As
there are seven spots left, we can satisfy the eight zeros,

8000000010

but now there is also a one in the number, and as there are no more
spots available, the one cannot be accounted for. Therefore, the second
last digit must be a zero. We can now look at the seven’s digit.

_______x00

Again, there are only two possibilities. If this number was one,
then the only possible location for the seven is in the zeros spot.

7______100

Again, the only logical places to put the extra five zeros are in
all of the positions except for the ones position (since we already
have a one).

7_00000100

Unfortunately, this condition cannot be satisfied because a one
in the one’s position gives us two ones, while a two in the ones
position is false. Thus, the sevens digit must be a zero and we can
continue onto the six’s digit.

______x000

Again, there are only two possibilities. If this number was one,
then the only possible location for the six is in the zeros spot.

6_____1000

Before the zeros are placed, consider the number of ones. A one in
the ones position was a one, then it will be false, therefore the digit
must be two or more. A value of three is impossible since 6+3+1*3 >
10, therefore the ones digit must be a two. Furthermore, to satisfy
the condition that three of the remaining four positions are zeros,
the two’s digit must be a one.

This leaves us with one possible answer of:

6210001000

Now we will attempt to eliminate all other possible answers.

If the six’s position was a zero, then the zero’s digit can be at most a
five.

5_____0000

The five’s digit then must be a one and the one’s digit must be at
least a two (since a one’s in the one’s position means that there are two
ones in the number!).

52___10000

At this point, we have a problem, since we can only have one more zero in
the number, the remaining digits must be at least ones. Since the sum of
digits is already eight, the most that the remaining digits can be are
also ones! However, this means that there will be three ones in the
number, and there are no threes in the number, which means that this is
not the correct number. Therefore, the five’s digit must be a zero, while
the zero’s digit can be at most a four.

4____00000

It is obvious already there is a contradiction with this number. The
zeros digit maximum is already less than the number of zeros in the
digit, therefore, we cannot add any more zeros to the number! At this
point, we can safely conclude that there will be no more solutions to
the problem, which means that the solution that’s been found already
is unique.

In conclusion, there is indeed a solution to the problem. The
solution is 6210001000 and this number is also unique.

Smaller Numbers

This problem can be restated for a smaller number of digits, I have
not done an exhaustive search for such numbers, but I have a list of the
ones that I have found based on the number of digits in the number:

1.   none
2.   none
3.   none
4.   1210, 2020
5.   21200
6.   none
7.   3211000
8.   42101000
9.   521001000
10.   6210001000

Stay tuned for another number digits puzzle coming up in a couple of days!

## 4 thoughts on “Number Digits Puzzle #1 – Solution”

1. Anilkumar says:

I solve the puzzle programatically which wrote in java
code:
package testapp;
public class NineDigitMagic
{
public static void main(String args[]){
long globalcount=0;
for (int i=987654321;i>=123456789;i–){
globalcount++;
String s=i+””;
boolean unique=(s.matches((“^(?!.*(.).*\1)\d{9}”)));
boolean zero= !(s.contains( “0” ));
if(zero&&unique){
int count =0;
for(int inner=9;inner>=1;inner–){
if(Integer.valueOf(s.substring(0,inner))%inner==0)
{
count++;
}
}
if(count==9)
{
System.out.println(i+” is magic number”);
}
}
}
System.out.println(“globalcount”+globalcount +”times “);
}
}

Output:
Result is : 381654729 is magic number

Like

2. Anilkumar says:

The code above gives The Nine digit number .

Like

3. Anilkumar Munaganuri says:

OUTPUT FOR ABOVE SNIPPET:
381654729 is magic number
globalcount864197533times
BUILD SUCCESSFUL (total time: 14 minutes 0 seconds)

Like