# The missing number

The integer numbers from 1-30 are mutually communicated to you one by one in a random order (one number about every 5 seconds). However exactly one of those numbers is not communicated.

What is a good strategy to find this missing number?

• That questions is way too broad and will bring a lot of speculative answers. – rhsquared Jan 22 '20 at 16:29
• Not an answer to the actual question, but my father had a card trick where you remove one card and he quickly flips through the pack and tells you the missing card. How he did it was to count the ranks/pips in his head, knowing that a complete pack should sum to 364. To make it easier, he would drop the 100s digit. He would count the suit on 4 fingers, advancing 1 for hearts, back 1 (forwards 3) for clubs, forwards or backwards 2 for diamonds (whichever easier), and no action for spades (forwards 4), again knowing which finger it should stop at. – Weather Vane Jan 22 '20 at 18:38

I would:

Exclusive-or each incoming number with a variable ($$n$$) initialised to zero.

Then after the final number came in:

Exclusive-or $$n$$ with $$31$$ yielding the missing number.

• This seems surprisingly workable, since it takes only 5 fingers to keep track of the running result, and the final operation with 31 is just "flip all". (Or if the missing number happens to be 4, "flip the bird".) – Bass Jan 22 '20 at 16:31
• @Bass Yeah, that's hilarious! :-) – Paul Evans Jan 22 '20 at 16:33

My strategy would be to

Add the numbers to a running total, as I receive them, as well as keeping count of the numbers received.

Then

The sum of the numbers from 1 to 30 is 465, so, once I have received 29 numbers, I take the result of the sum from 465 to find the missing number.

• Exactly what I would do too, although I'm not sure the 429-threshold holds, since if the missing number is (e.g.) 1 and the penultimate number given is (e.g.) 2, you wouldn't know which one of these two numbers was missing when your count got to 462, even... – Stiv Jan 22 '20 at 14:25
• @Stiv oh yes, true, I guess you would need to keep count too. – hexomino Jan 22 '20 at 14:36
• In fact, I guess this entire question just boils down to 'just keep count' in a way! You would achieve the same by rot13(yvfgvat gur ahzoref 1-30 ba n cvrpr bs cncre naq pebffvat rnpu bar bss nf vg nevfrf, ovatb fglyr). Perhaps the OP intended for the numbers to be randomly listed 'with replacement', otherwise I'm now struggling to see the puzzle-ness of this question... (I've started over-thinking it now - this is dangerous...!) – Stiv Jan 22 '20 at 14:42
• Indeed, you can do the whole calculation modulo $31$, so that the last step is just negation. – Greg Martin Jan 23 '20 at 6:56

Write down the integers from 1 to 30 on a card. As each comes in, cross it off. The one that remains not crossed off is the one you didn't receive. This solution allows for repeats. (The question isn't 100% clear about whether there can be repeats and the preexisting answers here don't allow for them.)

• Since nothing is told what constitutes a good answer, this one is as good as any other. Simple and straightforward. Probably the safest. – Florian F Jan 24 '20 at 15:59