Inside the ComputerProgramming
The Fencepost Puzzle
A 10-meter fence with a post every meter needs 11 posts
A 10-meter fence, a post every meter. Easy: 10 posts, right? Programmers fall into this exact trap all the time.
You'll find out
- Where the extra post comes from
- Why code counts from zero
- The one-symbol bug in a loop
Why it matters
Off-by-one slips are a classic bug in code, and they hide in calendars, page counts and hotel stays too.
Play this lesson
Free to play in your browser or on iPhone