There are some simple math problems that can stump a lot of people, like the “bat and a ball” question that I shared a few years ago. This is a related problem:
- If you want to build a fence in a straight line that has 10 sections, how many fence posts do you need? The answer isn’t 10, but 11.
- Or suppose you’re building that same fence with 10 sections, but this time with each end connected to a house. Now how many posts do you need? It’s just 9.
This kind of issue comes up quite a bit. For another example, suppose you want to deposit four checks at the bank, but you need to wait five minutes between each deposit. How long will it take? It’s not 20 minutes like it seems at first glance, but just 15.
This is commonly known as the fence post error, or the off-by-one error. When counting things like this, it’s easy to get off by one in either direction because we’re counting the wrong thing. This surfaced a few years ago with this meme that went around:
The teacher’s logic was counting the number of cuts, which is what was measured by time, but the number of boards was a slightly different equation.
Presh Talwalkar explains it very well in this video:
This problem shows up in computing quite frequently, because computers often start counting at 0. If you have a program that was counting 4 apples, it would have a “3” saved in that spot because counting to four goes:
0,1,2,3
It’s a super easy mistake to make in all of those scenarios, and it’s something I’ll try to keep in mind when fence post-related questions pop up in the future.
Leave a Reply