Fence posts
You are building a straight fence 100 metres long, with a post every 10 metres, including one at each end. How many posts do you need?
Show hint
Try a tiny version first: a 10 metre fence with a post every 10 metres.
Show solution
11 posts. There are 10 gaps of 10 metres, and one more post than gaps.
This mistake is so common in programming it has a name: the off-by-one or fencepost error. In Python, range(0, 101, 10) gives the 11 post positions, while range(0, 100, 10) gives only 10.
Want a problem like this every day? See today's problem and keep a streak going.