Quick, how many discrete values are between zero (0) and one hundred (100)?
I’ll wait here while you count...
Possible correct answers, depending on how you interpreted the question and how you count, are:
Why so many answers?
This is a classic example of a fencepost error, also commonly known as an off-by-one error. It’s all about how you count!
Let’s discuss each of the above answers one at a time.
Ninety-nine
An answer of 99 indicates that you interpreted the word "between" to mean that we wanted the values from 0-100, exclusive. Meaning, not counting the end points of 0 and 100. In mathematical notation you would write this as (0-100), where the curved-parentheses mean open-ended interval.
One hundred
An answer of 100 is probably the most common answer to this question. Most folks just do a simple subtraction in their head and arrive at 100. Simple, right?
However, that only works if one endpoint is being counted inclusively, and the other exclusively. This is could be written as:
Where the square parenthesis represents a closed-ended interval, meaning the end point in inclusive to the range.
One hundred one
As you might have guess by now, an answer of 101 would mean you counted the range inclusively, counting both endpoints and each integer in between them. This can be written as [0-100].
Infinity
And finally... ∞. I threw this answer in there for the smart-asses in the crowd who would note that while I did qualify the question with the word discrete, I left it a bit ambiguous by using the word value, rather than something more concrete like integer.
However to quote the source
Discrete mathematics, also called finite mathematics or Decision Maths, is the study of mathematical structures that are fundamentally discrete, in the sense of not supporting or requiring the notion of continuity. Most, if not all, of the objects studied in finite mathematics are countable sets, such as integers, finite graphs, and formal languages.
So I could argue that it was implied that we were only interested in counting the integer values within the range. Either way, I don’t want to start a holy war over semantics and mathematical notation... for Phil and Jeff would likely destroy me. But I digress...
And the point is...?
The point is we, the genius software engineers we are, need to be careful even when it comes to the simple stuff... like counting. Simple counting mistakes like this often lead to some of the hardest bugs to track down - sometimes they are even the root-cause of those phantom bugs that we just can’t explain.