First off, I have no idea why this question works so well. I don't even have a good theory. All I have is an incredible correlation between answering this question correctly and being a really strong programmer.
The question was suggested to me by someone I respect a lot. I replied that it seemed too easy but he suggested I try it. He's a smart & imaginative guy so I started asking it of people I interview.
The interview process at virtually every company I have worked at has been 3 – 4 hours long. We ask basic programming, we ask brain teasers, we have them bring in some code they are proud of and spend 45 minutes having them take us through what they did and why. And 99% of the time, getting this question right or wrong predicts if they will pass the 3 – 4 hour process.
Question: For the integers between 0 and 100 (i.e. 1, 2, 3, …, 100) – how many have the digit 7 in them?
Answer: In the first comment below – answer it before reading below.
Keep in mind programming skill is just one of the skills you need to interview for (albeit, a critical one). So this is not the single question that answers if you should hire someone. You still need to determine if they work well with others, can make the right compromises and trade-offs to deliver a quality product – on time, etc. But to measure their technical ability, if I only got to ask one question, this would be it.
As to why it is such a good predictor – I have no idea. But before you dismiss it, try it.