This method is ingenious...
Can you explain why this works though?
I'll use an example, it'll be much easier to see I think with an example.
Take the letters of the word MATHS and arrange them so the 'A' always comes after the 'M'.
Fix the 'M' in the first spot:
M A _ _ _
M _ A _ _
M _ _ A _
M _ _ _ A
So there are 4 ways to do this, now fix the M in the 2nd spot:
_ M A _ _
_ M _ A _
_ M _ _ A
So there are 3 ways to do this, now fix the 'M' in the 3rd spot:
_ _ M A _
_ _ M _ A
So there are 2 ways, and finally fix the 'M' in the 4th spot:
_ _ _ M A
So there is only 1 way.
Amount of ways = 1 + 2 + 3 + 4 = 10
This is just the 4th triangular number. If we used the letters ABCDEF and had B after A, it would be the 5th triangular number, and so on, hence it is the (n-1)th triangular number when there are n letters.
Now consider MATHS again, and say we want A to be after M, and T to be after A, so in this order - MAT:
Fix M in the first spot:
M A T _ _
M A _ T _
M A _ _ T
M _ A T _
M _ A _ T
M _ _ A T
Which is 6 ways.
So you should be able to see that when we fix M in the first spot, there are now only 4 letters instead of 5, and we want to arrange 2 letters again (A and T) like befor, so we can use the (n-1) triangular number, so since n is now 4, we have the 3rd triangular number, which is 1+2+3=6 as required.
If we fix M in the 2nd spot we get:
_ M _ _ _
So if we put A and T in there, the amount of ways will be the (n-1) triangular number, and we know there are only 3 spaces to put the A and T, so 'n' is now 3, hence it is the 2nd triangular number, that is 1+2=3.
If we fix M in the 3rd position we get:
_ _ M _ _
And now there are only 2 letters, so using (n-1) it is the 1st triangular number, hence there is only 1 arrangement with M in the 3rd spot (which should be obvious, it is _ _ M A T).
So the total arrangements when A comes before M, and T comes before A (M A T), is 6 + 3 + 1 = 3rd triangular number + 2nd triangular number + 1st triangular number = Sum of the first (n-2) triangular numbers (remember that 'n' is the total amount of letters in the word, in this case MATHS, so n=5, (n-2)=3, sum of first 3 triangular numbers).
If I then wanted it so that 4 letters are in order, for example M A T H in that oder, it would just become the "sum of the sum of the (n-3) triangular numbers) since it will follow the same pattern as before.
Hope this makes sense lol.