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?
Puzzling Stack Exchange is a question and answer site for those who create, solve, and study puzzles. It only takes a minute to sign up.
Sign up to join this communityThe 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?
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.
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.
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.)