Find a 10-digit number where the first digit is how many 0's there are in the number, the second digit is how many 1's in the number, the third digit is how many 2's, and so on, until the tenth digit which is how many 9's there are in the number.

Click below to see the answer.

As a programmer, I'm often tempted to try to use a brute force approach to find the answers to number puzzles. That often works, but when brute force involves looping through all 10-digit numbers, you should probably look for a more elegant approach.

Let's see if we can construct the solution using logic instead. We can't have 0 zeroes, because then we would have to put 0 in the zeroes digit, and it would immediately be wrong. I'll start with a 9 in the zeros digit and the rest zeros, then make corrections until we hit on a solution.

90000 00000

Now we have a 9, so there should also be a 1 in the 9 column.

90000 00001

But now there aren't 9 zeroes, there are only 8. There's also a 1, which means we have to change the first and second digits.

81000 00001

Wait, now there isn't a 9, so we have to move that last 1 over. There are also two 1's, so we have to change the second digit.

82000 00010

That's closer, but now there is a 2, so we have to record it in the twos column. There are also fewer 0's, so we have to change the first digit as well.

72100 00010

Still not quite right. There are now only six 0's, so we have to change the first digit again. There's also no longer an 8. We can make both of these changes at once, giving us a final answer of

Yeah, seeing an answer right away in the comments could potentially ruin the fun. The button worked for me and I'm using Twitter's in-app browser on Android 5.0.1.

## 4 comments:

Pradeep,

Yes, that's the answer I came up with. Is the Show/Hide Answer button not working? If so, what device/OS are you using? I'd like to get that fixed.

Yeah, seeing an answer right away in the comments could potentially ruin the fun. The button worked for me and I'm using Twitter's in-app browser on Android 5.0.1.

Oh, I never realized there was a show answer button. It works fine.

Post a Comment