### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,367)
- misc (4)
- project euler (2)
- puzzle (90)
- puzzle# (48)
- site news (58)
- tantalizer (94)
- teaser (7)

### Site Stats

- 233,126 hits

Programming Enigma Puzzles

22 January 2014

Posted by on **From New Scientist #1308, 3rd June 1982** [link]

The number of people in the room was a perfect square. We were numbered consecutively from 0 upwards. We each had to think of a number which was chosen from 0, 1 or any power of 2 giving a number less than the number of people in the room. It turned out that the person number 0’s choice of number coincided with number of 0s chosen; the person number 1’s choice of number coincided with the number of 1s chosen; the person number 2’s choice of number coincided with the number of 2s chosen; the person number 3’s choice of number coincided with the number of 3s chosen (which of course was zero); and so on for all the people in the room.

How many people in the room?

[enigma163]

%d bloggers like this:

This Python 3 program runs in 52ms.

Solution:There were 36 people in the room.The people who chose a non-zero number are shown below. The remaining 32 people all chose 0.

There are actually two further solutions with 4 people in the room:

But we’ll be generous and suppose that the “and so on…” after person number 3 implies there are more than 4 people, which gives a unique solution. Although I think the puzzle could have made this clear.

For 49 people there are 7 possible numbers each person can choose from (0, 1, 2, 4, 8, 16, 32), so there are 42 people whose numbers don’t coincide with the choice numbers and must chose 0, hence there are at least 42 zeros. But this is more than the largest possible choice number. So there cannot be 49 people in the room.

For 64 people there are now 8 possible choice numbers (0, 1, 2, 4, 8, 16, 32, 64), so there must be at least 56 zeros, and the only choice number at least as large as this is 64. But there cannot be 64 zeros, as person number 0 would have to choose 64. So there cannot be 64 people in the room.

In fact by considering when:

or equivalently when the following equation is greater than zero:

we can see that there can be no solutions for greater than 64 people.

Of course, if you don’t trust the analysis, you can let the program consider squares up to 70710², at which point the number of people in the room would exceed 5×10

^{9}, which is greater than the number of people on the planet in 1982. This only takes 1.5s with the program above (or 168ms with an equivalent program running under PyPy).