**From New Scientist #2509, 23rd July 2005**

Joe asked Penny to think of four different positive digits and add up the 24 different four-digit numbers that could be made using the four digits. Then he asked her to subtract just one of the four-digit numbers from the total and write down the new total. When asked what number she had written down, Penny replied: “122??0.”

Joe didn’t quite hear the fourth or fifth digits. But he was able to work out the number Penny had subtracted.

What was that number?

[enigma1350]

### Like this:

Like Loading...

This Python programs runs in 48ms.

Solution:The subtracted number is 3754.Originally I computed the sum of all 24 possible numbers as [[

`6666 * sum(s)`

]], but as I had to generate all the permutations anyway (and there’s only 24 of them) it seemed to be a bit clearer to let Python determine the sum, and it doesn’t affect the runtime of the program.I reasoned as follows:

The partly heard number lies between 122004 and 122994.

Divided by 6666 that’s 18.3 to 18.45.

But one permutation of digits had been left out, so it’s reasonable to suppose the original digit sum was 19.

19×6666 = 126654, so the missing number lies between 3664 and 4654 and ends in 4.

The only one I can find in that range, with all digits different and summing to 19, is 3754.

Here’s a solution using the [[

`SubstitutedExpression()`

]] solver from theenigma.pylibrary, that treats the puzzle as a single alphametic expression.It is based on the observation that the sum of all permutations of

ABCDis6666 × (A + B + C + D).It runs in 160ms.