In this problem you must provide an accurate census of all the digits inside a given box. The problem is complicated by the fact that your census report also appears inside the box, thereby influencing the result. Here is the simplest form of the problem.
---------------------------------------------- | The number of 0's inside the box is: ___ | | The number of 1's inside the box is: ___ | | The number of 2's inside the box is: ___ | | The number of 3's inside the box is: ___ | | The number of 4's inside the box is: ___ | | The number of 5's inside the box is: ___ | | The number of 6's inside the box is: ___ | | The number of 7's inside the box is: ___ | | The number of 8's inside the box is: ___ | | The number of 9's inside the box is: ___ | ----------------------------------------------
Suppose you start to fill it in like this: there's only one 2, so you put a 1 next to the 2. But there are now two 1's, so you put a 2 next to the 1. But now there are three 2's... and so on. This problem eventually converges and can be answered as follows.
-------------------------------------------- | The number of 0's inside the box is: 1 | | The number of 1's inside the box is: 7 | | The number of 2's inside the box is: 3 | | The number of 3's inside the box is: 2 | | The number of 4's inside the box is: 1 | | The number of 5's inside the box is: 1 | | The number of 6's inside the box is: 1 | | The number of 7's inside the box is: 2 | | The number of 8's inside the box is: 1 | | The number of 9's inside the box is: 1 | --------------------------------------------
Count the numbers and you'll see the sums all work out. We will complicate this problem by adding some extra numbers to the top of the box.
Example
If
extras = 22222
then we can see by inspection that one solution is
census = [1 7 7 2 1 1 1 3 1 1]
as shown below
-------------------------------------------- | Here are some extra numbers: 22222 | | The number of 0's inside the box is: 1 | | The number of 1's inside the box is: 7 | | The number of 2's inside the box is: 7 | | The number of 3's inside the box is: 2 | | The number of 4's inside the box is: 1 | | The number of 5's inside the box is: 1 | | The number of 6's inside the box is: 1 | | The number of 7's inside the box is: 3 | | The number of 8's inside the box is: 1 | | The number of 9's inside the box is: 1 | --------------------------------------------
In general, your answer might not be unique. We'll just test whether you meet the criteria.
Looks like a neat problem, but I have a question on your example solution with no extra numbers: If I'm reading it correctly, there are supposed to be two 4s in the box. Where is the second 4?
Good catch James! Thanks. That was a data entry problem. Should be fixed now.
Nice problem! But I might have some misunderstanding on your problem. My own solution didn't converge on test case 6. Is convergence guaranteed? Could you provide an example solution for test case 6?
Hi Peng, and thanks for the note. I see your solutions now do quite well with all test cases! :-)
116 Solvers
123 Solvers
Generate a vector like 1,2,2,3,3,3,4,4,4,4
1513 Solvers
Find two triangular numbers whose sum is input.
46 Solvers
Van Eck's Sequence's nth member
264 Solvers