If I wanted to figure out for example, how many tutorial exercises I completed today.

And the first question I do is question $45$,

And the last question I do is question $55$

If I do $55-45$ I get $10$.

But I have actually done $11$ questions:
$1=45$, $2=46$, $3=47$, $4=48$, $5=49$, $6=50$, $7=51$, $8=52$, $9=53$, $10=54$, $11=55$.

Is there any way to know when I can just subtract. Or is the rule I always have to add $1$ when I subtract?

  • 1
    $\begingroup$ You have to count the number of exercises done today : i.e. those starting from the number 45 up to the number 55 (extremes included). Thus, the exercises you have not done today are those up to 44; conclusion: subtract from the last exercise done today the number of exercises not done, i.e. 44. $\endgroup$ – Mauro ALLEGRANZA Oct 24 '16 at 9:12
  • 1
    $\begingroup$ Just so you know, you are not alone. This is one of the two hard problems in computer science. ;) $\endgroup$ – jpmc26 Oct 24 '16 at 19:43

If you want to use pure subtraction, here's how you'd do it:

At the beginning, you were at the start of problem 45.

At the end, you were at the end of problem 55, which is the start of problem 56.

And $56-45=11$. You finished $11$ problems.

The reason for the offset is because you're measuring from different places from each problem - the start of 45, but the end of 46.

  • 10
    $\begingroup$ +1 for giving a rationalization of why the fencepost error occurs. $\endgroup$ – wchargin Oct 24 '16 at 12:03
  • 2
    $\begingroup$ @wchargin +1 to your comment for containing the phrase "fencepost error", because it's good for people to know the name of this very common error. $\endgroup$ – Gregory J. Puleo Oct 24 '16 at 19:06

Suggestion: if you'd done questions $1$ to $N$, you'd have done $N$ questions. So if you start at question $44$ and finish at question $55$, subtract $43$ from both $44$ and $55$ to reduce to the easy case where the question numbers begin with $1$.

  • 3
    $\begingroup$ This a good idea. In my maths exam I often double-guess myself whether I should add one or not (and waste exam time), so I will just follow this method every time. $\endgroup$ – K-Feldspar Oct 23 '16 at 23:03

You'll always need to add one in such cases. Consider - if you do problems 45 through 45, you'll have done 45-45 + 1 = 1 questions.


It depends on whether the range includes or not its endpoints. For example, let $n \in \mathbb{N}$. Then:

  • $45 \lt n \lt 55\quad$ has $\;55-45-1=9$ solutions;
  • $45 \le n \lt 55\;$ and $\;45 \lt n \le 55\quad$ both have has $\;55-45=10$ solutions;
  • $45 \le n \le 55\quad$ has $\;55-45+1=11$ solutions.

[ EDIT ] In the original post, the first question I do is question 45 and the last question I do is question 55 imply that the range is inclusive of both endpoints $45,55$ which falls in the latter case among the above, so the correct answer is $55-45+1=11$.

  • 1
    $\begingroup$ The question makes it quite clear that the range includes the endpoints. $\endgroup$ – Rob Arthan Oct 23 '16 at 22:58
  • 1
    $\begingroup$ I do still find the answer useful as it shows me in which cases I can't subtract (although I kind of knew this, I couldn't specifically write it down or explain it). $\endgroup$ – K-Feldspar Oct 23 '16 at 23:04
  • $\begingroup$ @RobArthan Thanks, edited my answer to clarify. $\endgroup$ – dxiv Oct 23 '16 at 23:04
  • $\begingroup$ Please don't use codeblocks for something which is not actual code. Quotemarks and emphasis or a quoteblock would work far better. $\endgroup$ – Nij Oct 24 '16 at 10:13
  • 1
    $\begingroup$ @Nij I don't think anyone could possibly mistake that for actual code, so there is no confusion about it. The reason code blocks are sometimes used for quotes is that there are no Inline Quotes, and the highlight is visually easier to follow than the alternatives. $\endgroup$ – dxiv Oct 24 '16 at 15:28

If you started at the question 15 and finished at the question 15; how many question have you answered?

Imagine a list of exercises to be done in order. Some of them are marked as done already. You start from the first unmarked question.

Every time you complete an excercise you mark it, thus increasing the number of the first excercise waiting to be done.

This way the number of excercises done in some time is an incremet of a number of the first excercise not done yet.
Since you started with question 45 (so 45 was the first question NOT done then) and you stopped after question 55 (so the first question NOT done yet is $56 = 55+1$ now), you have answered $(55+1)-45=11$ questions.

Put it another way:

when you started your work, the last question answered was number $44 = 45-1$, and now it is $55$; the number of questions you answered today is an increment of the number of questions answered: $55 - (45-1) = 11$.


What you are trying to calculate is the sum of exercises you did from question $a$ to question $b$. You have $1$ exercise per question so the number of exercises is : $$\underbrace{\sum_{a}^b 1}_{\text{Sum from a to b}} =\underbrace{\sum_{1}^b 1}_{\text{Sum from 1 to b}} - \underbrace{\sum_{1}^{a-1} 1}_{\text{Sum from 1 to a-1}} = b-(a-1) = b-a+1 $$ Therefore, if you did question 45 to 55 you have $a=45$, $b=55$, so you did $55-45+1=11$ exercises


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.