The first ten things have one-digit numbers, except the last one which has a two-digit number.
The second ten things have numbers starting with 1, except the last one which starts with 2.
The first thing in the first ten things has number 01, so “first” means simultaneously 0 and 1.
All of those go away with zero-based counting.
Also zero-based counting has many benefits for programming:
The first memory address is all zeroes, not 00000001.
The first grid cell originates at (0, 0), not (1, 1).
The idioms a[i / n], a[i % n], a[i * n + j] don’t work as well with one-based counting.
I think the underlying reason for all of those is the way modular arithmetic works. If a and b are positive integers, then the possible results of both a / b (integer division) and a % b (modulus) range from 0 rather than 1. Since digits in a number, indices in a sequence, etc. are often defined by these operations, zero-based counting feels more natural.
As to your problem, it can be solved by consistently using half-open ranges, which is another good idea that works well with mine :-)
Some inconsistencies with one-based counting:
The first ten things have one-digit numbers, except the last one which has a two-digit number.
The second ten things have numbers starting with 1, except the last one which starts with 2.
The first thing in the first ten things has number 01, so “first” means simultaneously 0 and 1.
All of those go away with zero-based counting.
Also zero-based counting has many benefits for programming:
The first memory address is all zeroes, not 00000001.
The first grid cell originates at (0, 0), not (1, 1).
The idioms a[i / n], a[i % n], a[i * n + j] don’t work as well with one-based counting.
I think the underlying reason for all of those is the way modular arithmetic works. If a and b are positive integers, then the possible results of both a / b (integer division) and a % b (modulus) range from 0 rather than 1. Since digits in a number, indices in a sequence, etc. are often defined by these operations, zero-based counting feels more natural.
As to your problem, it can be solved by consistently using half-open ranges, which is another good idea that works well with mine :-)