From “The Reinvigorated Programmer”: Are you one of the 10% of programmers who can write a binary search?

— 2 minute read

The Reinvigorated Programmer (Mike Taylor) quotes from Jon Bentley’s 1986 classic Programming Pearls:

Only 10% of programmers can write a binary search

Shocking indeed

Better yet, he has a coding challenge for you to take part in (post answers as comments):

Here are the rules:

  1. Use whatever programming language you like.
  2. No cutting, pasting or otherwise copying code.  Don’t even look at other binary search code until you’re done.
  3. I need hardly say, no calling bsearch(), or otherwise cheating :-)
  4. Take as long as you like — you might finish, and feel confident in your code, after five minutes; or you’re welcome to take eight hours if you want (if you have the time to spare).
  5. You’re allowed to use your compiler to shake out mechanical bugs such as syntax errors or failure to initialise variables, but …
  6. NO TESTING until after you’ve decided your program is correct.
  7. Finally, the most important one: if you decide to begin this exercise, then you must report — either to say that you succeeded, failed or abandoned the attempt.  Otherwise the figures will be skewed towards success.

If you haven’t yet, try it. Read just the article, but do not look at the others’ comments just yet.

After you have attempted this, there is his redux, on why coding exercises like this matter; and his redux of the redux, on why you should not test while attempting exercises like this. They are all worth a good read.