### by John Owen

#### Published Sunday December 06 (link)

Last year I was given a mathematical Advent calendar with 24 doors arranged in four rows and six columns, and I opened one door each day, starting on December 1. Behind each door is an illustrated prime number, and the numbers increase each day. The numbers have been arranged so that once all the doors have been opened, the sum of the numbers in each row is the same, and likewise for the six columns. Given the above, the sum of all the prime numbers is as small as it can be.

On the 24th, I opened the last door to find the number 107.

In order, what numbers did I find on the 20th, 21st, 22nd and 23rd?

From → Uncategorized

1. • The comment in line 49 is true – but, because row and column sums are even, the sum must be divisible by both 8 and 12.

I suspect that this does not affect the operation of the program – but perhaps the 12 in line 51 could be replaced by 24?

• Hi Tony,

You are right that I could increase the constraint to 24 but I would prefer to
stick with the least common multiple of the number of rows and columns as this
is the most obvious immediate constraint. It would improve the speed of the code
very slightly to add the additional constraint of even column sums but this won’t
change to results as this is already guaranteed by the code. This teaser seems
hard manually and using 24 rather than 12 here might help quite a lot in allowing
steps of 24 rather than 12 in checking the overall prime sum values.

2. Hi Brian,

You don’t report 24 different prime numbers.

• Thanks, corrected.

3. I think Line 48 should be:

The current situation gives 107 twice in ps at line 53.

• Thanks, corrected now.

4. I wrote my code withot seeing Brian’s; it is nevertheless surprisingly similar to his.
My efforts at removing elements from lists could be more elegant.
I changed exactly one line in my code after seeing Brian’s – see the comment below.

5. Removing the constraint that the column sums be equal gives the same result.

Any thoughts?

6. Hi John,

This is true for some row arrangements but not for others. If the programs are changed to allow multiple solutions, this shows that there are row sums for prime sums of 1080 (and higher) that do not allow equal sum columns. And this means that, in arriving at a solution, it is necessary to find an arrangement which provides both equal row and equal columns sums – finding equal row sums doesn’t necessarily provide equal column sums.

7. My point is that if you remove the words “and likewise for the six columns” from John Owen’s Teaser, and seek a solution on that basis, it has the same unambiguous solution as with those words present. The numbers for the days 20-23 will be the same.

Normally, each additional constraint in the Teaser statement reduces the solution space. It is not the case here.

For example in a calendar with equal rows such as:
[3, 5, 7, 47, 101, 107] 270
[67, 37, 71, 41, 11, 43] 270
[73, 13, 79, 17, 29, 59] 270
[83, 19, 53, 23, 61, 31] 270

There is no possible arrangement of the numbers in the rows giving equal column sums. But the Teaser solution is the same as if both row and column sums were equal such as occurs in the outputs of the above programs.

8. 