2
$\begingroup$

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?

$\endgroup$
  • 5
    $\begingroup$ That questions is way too broad and will bring a lot of speculative answers. $\endgroup$ – rhsquared Jan 22 at 16:29
  • 3
    $\begingroup$ 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. $\endgroup$ – Weather Vane Jan 22 at 18:38
16
$\begingroup$

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.

$\endgroup$
  • 4
    $\begingroup$ 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".) $\endgroup$ – Bass Jan 22 at 16:31
  • $\begingroup$ @Bass Yeah, that's hilarious! :-) $\endgroup$ – Paul Evans Jan 22 at 16:33
12
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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... $\endgroup$ – Stiv Jan 22 at 14:25
  • $\begingroup$ @Stiv oh yes, true, I guess you would need to keep count too. $\endgroup$ – hexomino Jan 22 at 14:36
  • 1
    $\begingroup$ 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...!) $\endgroup$ – Stiv Jan 22 at 14:42
  • 1
    $\begingroup$ Indeed, you can do the whole calculation modulo $31$, so that the last step is just negation. $\endgroup$ – Greg Martin Jan 23 at 6:56
6
$\begingroup$

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.)

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.