Advertisement

We need your help now

Support from readers like you keeps The Journal open.

You are visiting us because we have something you value. Independent, unbiased news that tells the truth. Advertising revenue goes some way to support our mission, but this year it has not been enough.

If you've seen value in our reporting, please contribute what you can, so we can continue to produce accurate and meaningful journalism. For everyone who needs it.

Abacus not required. abacus via Shutterstock

How to guess any number under 1,000 in ten steps or less

Here’s a fun party trick to hone in the weeks to come.

HERE IS A fun math party trick.

Tell someone to pick a number between 1 and 1,000. Your goal is to guess the number.

For each guess you make, your friend tells you one of three things: you guessed the number, your guess was high, or your guess was low.

Amazingly, if you guess properly, it is possible to get to any number your friend chooses in 10 or fewer guesses.

The trick to this is to constantly be cutting the amount of numbers you have to consider in half. This process demonstrates binary search, a foundational concept in technology. But more on that later.

How to guess the number in 10 steps or under

Suppose your friend chooses the number 334.

Your First Guess: In this game, your first guess should always be 500, halfway between 1 and 1000. So, you guess 500, and your friend tells you that their number is lower. Now you know that the number is somewhere between 1 and 500, and you have knocked out everything between 500 and 1000. You have, in one guess, already gotten rid of half the possibilities.

Your Second Guess:You know that the number is between 1 and 500, so you again take the halfway point between these two, and you guess 250. Now your friend tells you your guess is too low, so you know the number is somewhere between 250 and 500. In just two steps, you have knocked out 750 numbers, and are just looking at about 250 numbers, a quarter of our original set.

Keep Doing This: Your next guess is halfway between 250 and 500, or 375. Your friend tells you this is too high, so now you know that the number is between 250 and 375. You have reduced your range to about 125 possibilities.

The fourth guess is the midpoint of 250 and 375: Unfortunately, this is a decimal number – 312.5, but we can simply round up to 313. This guess is too low, but we have again eliminated half the remaining numbers, leaving us with the 61 numbers between 313 and 375.

Your fifth guess is halfway between 313 and 375: 344. Again, this is too high, but you’re down to the 30 numbers between 313 and 344.

Your sixth guess is halfway between 313 and 344: 328.5, rounded up to 329. Too low. You know the number is between 329 and 344, leaving just 14 possibilities.

Your seventh guess is halfway between 329 and 344: 336.5, rounded up to 337. Too high, but you’re getting close — only the seven numbers between 329 and 227 are left.

Your eighth guess is halfway between 329 and 337: 333. Juuust too low. But now there are just three remaining possibilities — you know the number is between 333 and 337, so it must be one of 334, 335, or 336.

Your ninth guess is the middle option of 335, and you are told that your guess is too high.

And now you know that the number is between 333 and 335. There is only one such number, and so your tenth, and final guess, is 334, your friend’s number.

This process will work for any number between 1 and 1000, and you will always find the number within 10 guesses.

Binary search

This game is a simple example of a binary search process.

This works well for any ordered list, like a directory of employees at a corporation, ordered by name. Suppose we are trying to find a particular name on the list.

We start by comparing the desired name to the middle name in the list. If they match, then yay! We are done.

If the middle name comes after the desired name, we throw out the second half of the list, and just look at the first half.

If the middle name comes before the desired name, we do the opposite — dump the names before the middle name, and just search the second half of the original list. Then we just keep repeating this process, throwing out half the remaining names each time, until we find our name.

This is such a simple, recursive process that it is ideally suited to being run on computers, and this is indeed how most database systems search through sorted lists of data.

One of the coolest things about binary search is that the number of steps you need to find your target increases logarithmically with the size of the set you are looking in. What this means is that if you double the size of your set, you only wind up adding one extra step. If I wanted to find a number between 1 and 2000, my first guess is going to be 1000 (halfway between 1 and 2000), and then I’ll be looking at either the numbers between 1 and 1000 or between 1001 and 2000, and we are back where we started — trying to find one number among a thousand numbers.

Extending this out, if we wanted to find a number between 1 and 1,000,000, we actually only need 20 steps to get to the number. For those of you familiar with logarithms, this is because the base 2 logarithm of 1,000,000 is just under 20.

Processes like this that add steps at a logarithmic rate with respect to the size of the input are pretty rare — usually, if I double the size of my input, I at least double the number of steps I need to take to solve my problem, and often need to add many, many more steps than that.

Binary search is a great example of using a very simple concept — repeatedly cutting my search region in half by always guessing the middle number — and getting a very powerful tool from that concept. This is one of the central, big ideas in math: Start with a simple notion, and discover all the interesting, often surprising, implications of that notion.

- Andy Kiersz

Maths Week puzzles>
Kids who do well on this test may have unrealised potential>

Readers like you are keeping these stories free for everyone...
A mix of advertising and supporting contributions helps keep paywalls away from valuable information like this article. Over 5,000 readers like you have already stepped up and support us with a monthly payment or a once-off donation.

Published with permission from
View 28 comments
Close
28 Comments
    Install the app to use these features.
    Mute Mac Mock
    Favourite Mac Mock
    Report
    Nov 24th 2013, 5:20 PM

    Next week –

    How to guess any number between 1-5 in 6 steps

    348
    Install the app to use these features.
    Mute Elma Phudd
    Favourite Elma Phudd
    Report
    Nov 24th 2013, 5:10 PM

    Is this not blindingly obvious?

    211
    Install the app to use these features.
    Mute robby rottenest
    Favourite robby rottenest
    Report
    Nov 24th 2013, 5:14 PM

    Not to me. I’m a maths moron.

    90
    Install the app to use these features.
    Mute David Sharp
    Favourite David Sharp
    Report
    Nov 25th 2013, 10:05 AM

    Yeah it’s fairly obvious! Take logical steps…. Done!! Must be a slow news day!!

    4
    Install the app to use these features.
    Mute Carina Clarke
    Favourite Carina Clarke
    Report
    Nov 24th 2013, 5:39 PM

    Hopefully not blindingly obvious, my son is fine tuning his act all ready to clean out his extended family of 2€ a go at the next clan gathering. He is on the make.

    127
    Install the app to use these features.
    Mute Symbolism
    Favourite Symbolism
    Report
    Nov 24th 2013, 5:28 PM

    You seriously need to get out more if this is your idea of party fun.

    88
    Install the app to use these features.
    Mute Dave Caplice
    Favourite Dave Caplice
    Report
    Nov 24th 2013, 6:56 PM

    You lost me at “math party trick”

    49
    Install the app to use these features.
    Mute Nun on Yokes
    Favourite Nun on Yokes
    Report
    Nov 24th 2013, 5:42 PM

    Great party trick alright. And afterwards play “guess which granny is in the churn by smelling the ashes”. I would say allot of people wash their hair around the anniversary of your birth ; )

    34
    Install the app to use these features.
    Mute Symbolism
    Favourite Symbolism
    Report
    Nov 24th 2013, 5:52 PM

    What a place to keep their ashes !

    22
    Install the app to use these features.
    Mute Richard Toolan
    Favourite Richard Toolan
    Report
    Nov 24th 2013, 5:44 PM

    Binary search!

    24
    Install the app to use these features.
    Mute Jonathan Boyle
    Favourite Jonathan Boyle
    Report
    Nov 24th 2013, 8:09 PM

    When’s your next party, can’t wait!

    23
    Install the app to use these features.
    Mute Paul
    Favourite Paul
    Report
    Nov 24th 2013, 5:11 PM

    Wow you have unlocked the possibilities if probability

    20
    Install the app to use these features.
    Mute Daniel Dudek Corrigan
    Favourite Daniel Dudek Corrigan
    Report
    Nov 24th 2013, 5:31 PM

    Actually, no…

    27
    Install the app to use these features.
    Mute Phill
    Favourite Phill
    Report
    Nov 24th 2013, 5:46 PM

    Actually no. That is not how most databases search for data.

    They use indexes. And in the case of a non indexed column they do a table scan which scales linearly, not logarithmically.

    17
    Install the app to use these features.
    Mute Emilio
    Favourite Emilio
    Report
    Nov 25th 2013, 9:35 AM

    And did you know that plenty of indexes are made based on binary trees and not on hashes, as you are probably thinking? Some data types are better suited to be indexed with binary trees, other with hashes.

    1
    Install the app to use these features.
    Mute Phill
    Favourite Phill
    Report
    Nov 25th 2013, 11:54 AM

    B Tree != binary search

    1
    See 2 more replies ▾
    Install the app to use these features.
    Mute Emilio
    Favourite Emilio
    Report
    Nov 25th 2013, 12:01 PM

    A b-tree is a generalisation of a binary search.

    1
    Install the app to use these features.
    Mute Phill
    Favourite Phill
    Report
    Nov 25th 2013, 12:25 PM

    It is misleading to suggest the algorithm presented in this article is the way that databases look up values. B Trees are much more complex data structures than a linear sorted list.

    This isn’t really the forum for this discussion though so I’ll tap out!

    1
    Install the app to use these features.
    Mute Alan O Reilly
    Favourite Alan O Reilly
    Report
    Nov 24th 2013, 11:21 PM

    Rather a game of snap meself…… :/

    10
    Install the app to use these features.
    Mute Hank Schrader
    Favourite Hank Schrader
    Report
    Nov 24th 2013, 10:14 PM

    This is a party trick.. So can we not just hold them down and tickle them until they tell us.. either that or they pee themselves.

    7
    Install the app to use these features.
    Mute Stephen Lambkin Moroney
    Favourite Stephen Lambkin Moroney
    Report
    Nov 25th 2013, 12:59 AM

    Is it not decimal search? Binary 1′s abd 0″s? ok i need to get out more!

    6
    Install the app to use these features.
    Mute Stephen Lambkin Moroney
    Favourite Stephen Lambkin Moroney
    Report
    Nov 25th 2013, 1:00 AM

    And *

    1
    Install the app to use these features.
    Mute Emilio
    Favourite Emilio
    Report
    Nov 25th 2013, 9:39 AM

    It is called binary search because you divide the search in 2 on every step, not because of ones and zeroes.

    4
    Install the app to use these features.
    Mute David Sharp
    Favourite David Sharp
    Report
    Nov 25th 2013, 10:07 AM

    Next week, how to count to 3 in two steps….2,3!! Boom!!!

    3
    Install the app to use these features.
    Mute Mick Collins
    Favourite Mick Collins
    Report
    Nov 25th 2013, 11:27 AM

    Lmao

    1
    Install the app to use these features.
    Mute Marie Louise Ni Riain
    Favourite Marie Louise Ni Riain
    Report
    Nov 25th 2013, 3:07 AM

    Boring Sunday was it?

    3
    Install the app to use these features.
    Mute Fergal McDonagh
    Favourite Fergal McDonagh
    Report
    Nov 25th 2013, 2:24 PM

    The long winter evenings will simply fly by……….

    2
    Install the app to use these features.
    Mute M Sharjeel Ashraf
    Favourite M Sharjeel Ashraf
    Report
    Nov 25th 2013, 12:02 PM

    So you make 9 wrong guesses before finally getting to the right answer. !! Better luck next time

    1
Submit a report
Please help us understand how this comment violates our community guidelines.
Thank you for the feedback
Your feedback has been sent to our team for review.
JournalTv
News in 60 seconds