Find a 10-digit number, where each digit represents the number of that ordinal number in the whole number. So, the first digit represents the number of 0's in the whole 10 digits. The second digit represents the number of 1's in the whole 10 digits. And so on. The first digit is not a 0.As I promised at the end of the "brain only" post, we'll do better than simply finding an answer, we'll find all of them (with the aid of a computer).
Making the Problem SmallerWithout any thinking, there are 9 billion (9⋅109) total choices. This is not only intractable for the human brain, but becomes difficult for a computer too. A 3 GHz processor in the most optimal case can only perform 3 billion operations per second but there is a lot of counting, lists to create, and otherwise to find a number which fits the criteria. To start, we write our number as
Since there are 10 digits in total and each of the digits represent a subcount of occurrences, the total number of occurrences can be represented as the sum:
Additionally, (for example) since each 3 contributes a value of 3 to the digit sum, we must also have
This second equation (which requires the first to make sense) limits our choices of digits a great deal:
The last four are obvious since (for example) 2⋅6>10. We can also say that d5<2. It is clearly no bigger than 2 but in the case that d5=2 we'd also have d2>0 meaning 2d2+5d5=2d2+10>10. Thus to brute force the problem we can choose digits 5 through 9 (5 digits in total) from the 32 (25) different possible ways to make them 0 or 1.
Listing All ChoicesNow for the fun part: programming (in Python). We now have 90,000 (9⋅104) choices for our first 5 digits and 32 choices for our last 5 digits. We can use Python's range(10**4, 10**5) to represent the 5-digit numbers between 10,000 and 99,999 (inclusive). For the 32 choices for the last 5 digits, we use itertools.product. To see it in action on a smaller set of data: When we ask for 5 repeated copies of the tuple (0, 1) we get 32 possible 5-tuples as expected:
Checking CandidatesBefore we can iterate through all of our combinations, we need a way to check if a given number fits the criterion. To do that we implement This takes a list of digits, so as we loop over all choices, we'll turn them into lists.
Exhaustive SearchNow we can use our accumulated tools, loop through all choices and print any matches As luck would have it, the output is simply In other words, the only number which fits the criteria is the one we found with our brains alone: