+88*87*86*85*4 (1 repeated note)
It's 10, not 4. You aren't considering the possibility that it might not be the first note that is repeated. (There are 4 ways of repeating the first note, 3 ways of repeating the second, 2 of repeating the third and one of repeating the fourth; it's that triangular number again).
= 4926942328
... so you've managed to get a number that's
lower than the answer we've agreed for only zero or one repeats.
However, you correctly point out that we haven't considered cases where the repeated note is repeated
more than once. Let's do those. We've already considered no repeats and one repeat (one of the notes occurs exactly twice).
I'm going to denote the kth triangular number by T(k) now, because it's quicker.
Now, we can generate all possible 5-note tunes where one note occurs exactly three times by inserting notes as we did before. Take all possible 4-note tunes with exactly one repeat. This is easy, we already have a general formula for that. With r=4 there are nP
3*T(3) of them, or 88*87*86*6. We can now insert a new note in any of 5 places as before, however we don't have a choice as to which note now, because it has to be the one that's already been repeated. Also, since there are 3 occurrences of the same note each new tune can be generated in 3 ways (e.g. ABACA can be made from BACA, ABCA or ABAC), so we must divide by 3. In other words, there are 88*87*86*6*5/3 new tunes, or in general, nP
(r-2)*T(r-2)*r/3 tunes of r notes with one note repeated twice.
For the next step, using the formula from the previous paragraph with r=4, we get 88*87*3*4/3 4-note tunes to expand. Now each new tune can be generated in 4 ways, so we need to multiply by 5/4 and we get 88*87*3*4/3*5/4 new tunes, or nP
(r-3)*T(r-3)*(r-1)/3*r/4 in general.
The last step (quiet at the back there) in the same way takes 88*1*3/3*4/4 tunes (since R(1)=1) and expands them to give 88*1*3/3*4/4*5/5. Or nP
(r-4)*T(r-4)*(r-2)/3*(r-1)/4*r/5 in general.
Of course, the last step reduces to just 88 tunes, which is obviously the case as these are the tunes with 5 notes the same, so the only choice is the starting note.
I'm going to try to lay everything out neatly using the typewriter font now. We've got
88 * 87 * 86 * 85 * 84 +
88 * 87 * 86 * 85 * 10 +
88 * 87 * 86 * 6 * 5/3 +
88 * 87 * 3 * 4/3 * 5/4 +
88 * 1 * 3/3 * 4/4 * 5/5tunes in total. If I've not made a mistake entering it into the calculator that comes out as 5267366368. It isn't a very interesting number but it is a very interesting table we've got above. You might say that, for each row, the 88,87 ... numbers handle the unique notes, the 1,3,6,10 choose a note to repeat, and the fractions distribute the repeated notes among the others.
You can generate longer and longer tunes by adding numbers to the right (and adding a new row at the top to be the "all unique" case. The bottom row will always be 88 because it'll always be multiplied by 1. Not surprising since there's only really one note to choose. The next row up is more interesting. No matter how many notes we add, all the numbers in it will always cancel out except the first two and the last. You can explain this by, for r notes:
Choose a note (88) and repeat it r-1 times.
Choose a different note (87).
Choose a place to put the new note (r).
These are the r-note tunes with all the notes the same except one, and there are always 88*87*r of them.
I don't know if there's a simple formula for the total number of possible tunes in the general case, allowing only one note to be repeated but that any number of times. I haven't worked it out yet. Feel free.