Glaring mathematical error in _The Sentinel_ by Lee and Andrew Child

The clock is ticking, and Jack Reacher has to get into the bad guy’s house. There is a big, strong iron gate and a numeric keypad to open it. Reacher knows the access code is four digits long, and there are therefore “ten thousand permutations”. So far, so good. He blows some dirt onto the keypad, revealing smudges on the zero, the two, and the four. Now there are eighty-one permutations…

…what? Since all three digits occur in the combination, there are obviously only thirty-six possibilities. Something Reacher, who spends an inordinate amount of time thinking about mathematical puzzles and is a bit of prodigy, would know immediately.

The theme here is, failure to double-check facts that your fictional character would certainly know.

There are 81 combinations. 3 x 3 x 3 x 3.

Surely not. If the combination were “0000”, why would three of the keys have dust on them, instead of just one?

I’m with the OP. Yes, we need to make a few assumptions to arrive at 36 possibilities, but those assumptions seem consistent with the information presented. As follows:

The four-digit code contains the digits 0, 2, and 4.

Therefore, one digit appears twice.

Thus, the sets of possible numbers are:

0024
0224
0244

The repeat digits can appear in 6 positions:

0 0 x x
0 x 0 x
0 x x 0
x 0 0 x
x 0 x 0
x x 0 0

Each of those 6 different configurations allows two ways the digits could be filled in. For example, the first one could be 0024 or 0042.

So, we have 3 times 6 times 2 possible codes, which is 36.

X024 0X24 02X4 024X
X042 0X42 04X2 042X
X204 2X04 20X4 204X
X240 2X40 24X0 240X
X402 4X02 40X2 402X
X420 4X20 42X0 420X

= 24
x3 = 72

If X is 0, then your first two are the same, and your last two are the same, and so on.

I also got 36, though via a more onerous path.

I started with 3x3x3x3 = 81, but wanted to subtract out sequences that didn’t include all three digits. We can do that by calculating the permutations of drawing 4 from 2 with replacement, so pairwise

(1,2) → 2x2x2x2 = 16
(2,3) and (1,3) also = 16
BUT
three of the sequences are duplicated in those pairwise calculations (1111, 2222, and 3333 each show up twice in those permutations), so

81 - 48 + 3 = 36

Very much the long way around.

(hugs)

This is why I come here.

And the number of permutations is always 42. Thought this was settled?

I used Excel to figure out my answer. Listed out all 81 possible permutations of 4 digits using 0, 2, or 4, then counted how many times each of the 3 options were used and then filtered out any that didn’t use each of the 3 options at least once. I also came up with 36 to agree with a few posters above.

Andy Weir made a very similar mistake in Artemis: Four-digit code, containing three distinct digits. Except that he (or she; it’s first-person from the female protagonist) calculated it at 54.

And then, of course, figured out the single value for the code, based on what the three digits were and what she knew of the person who set it.

Okay – it’s 36.

It goes almost without saying that Reacher reasons what the code is on the first try:

In Reacher’s experience people often used dates as code numbers. They’re easy to remember. And they often have some kind of sentimental significance. In which case the first digit would have to be zero. The second would have to be two or four. And the final pair could not both be zero. Now he was down to ten possibilities. Or possibly only one. Reacher remembered the black Mercedes…

The correct number (36) is clear from the above posts, but in case anyone is interested in seeing a complete enumeration of possible solutions, I spent about 30 seconds writing a Python script to print them out. They are:

0 0 2 4
0 0 4 2
0 2 0 4
0 2 2 4
0 2 4 0
0 2 4 2
0 2 4 4
0 4 0 2
0 4 2 0
0 4 2 2
0 4 2 4
0 4 4 2
2 0 0 4
2 0 2 4
2 0 4 0
2 0 4 2
2 0 4 4
2 2 0 4
2 2 4 0
2 4 0 0
2 4 0 2
2 4 0 4
2 4 2 0
2 4 4 0
4 0 0 2
4 0 2 0
4 0 2 2
4 0 2 4
4 0 4 2
4 2 0 0
4 2 0 2
4 2 0 4
4 2 2 0
4 2 4 0
4 4 0 2
4 4 2 0

Well, once you remember the black Mercedes…

I am seriously going to remember this thread the next time I write a scene involving numbers, and imagine you guys getting ready to critique my math:

Reacher blew some dirt onto the keypad, revealing smudges on the zero, the two, and the four. Okay, now the possible permutations were… a lot easier.

Would blowing dirt on a keypad really reveal anything?

Potentially. Human skin contains oils, which could leave residue. I suppose it would depend on the type of material that the keypad buttons were made from, but that type of scenario is at least theoretically plausible.

That’s how I figured it, but from there, I used the fact that the number of permutations of n objects, in which k of them are identical, is n! / k!. Thus, 3 * (4! / 2!) = 3 * (24/2) = 36.

That’s what I love about statistics - the formulae make perfect sense and can be derived by breaking problems down into small, logical chunks and then piecing together algorithms. I had to take graduate level statistics to get my master’s degree, and even though I was a bit slow to work my way through it all, I enjoyed learning, because it was such a pure exercise in logic.

Anyway, I have long since forgotten 95% of the formulae I was taught, so I couldn’t do it the way you did. But I still love statistics, even if the specifics I was taught are hazy now.