24 choices for the first of the high priority letters (B-Y), and then there's (23, 22, ..., 1) second choices if the first one is (B, C, ..., Y). Thus, 23 * 24 / 2 = 23 * 12 = 276, I think.
In the context of combinatorial mathematics, stars and bars is a graphical aid for deriving certain combinatorial theorems. It was popularized by William Feller in his classic book on probability. It can be used to solve many simple counting problems, such as how many ways there are to put n indistinguishable balls into k distinguishable bins.
== Statements of theorems ==
The stars and bars method is often introduced specifically to prove the following two theorems of elementary combinatorics.
=== Theorem one ===
For any pair of positive integers n and k, the number of k-tuples of posi...
Let's go back to the example of P=2, N=3. One possibility is HHL (after sorting), and we have three distinct choices for the high priority letters, yeah? They yield ABC, ACB, BCA. The first is already sorted so is not distinct from the original.
With a given arrangement of bars, a group of size X will have N choose X possibilities for choosing the letters in that group, minus 1 because there is one selection of letters that isn't different from the original permutation.
And that applies to all but the last group since once the other groups have been determined, there's no more choice available.
Let's take the HHL example again. The first group has two items, so that's (3 choose 2 - 1) = (3 - 1) = 2, as expected.
Hrm wait, that's not a good way to do it since the available letters shrinks for each successive group.
Okay, better way: consider all N! permutations. Each group of size K defined by the bars divides this total by K! (because all permutations of letters within a group are the same after sorting).
So with HHL, the total is N!/(K_1! K_2!) = 3!/(2! 1!) = 3. Minus 1 for the permutation that's the same as the original.
I realized where my algorithm went wrong, and it's slightly different than what you are describing, I think
Consider HLH
Unlike HHL (which produces ABC), it produces ACB
However, when we move up to 3 priorities: We have another equivalency
HLM is equivalent to HLH
I need to count not just the number of strings that are equivalent to ABC...Z, but any string that is equivalent to a string generated by P-1 priorities
@NathanMerrill Oh man, that's true. Well, partially. By my syntax, HHL and HML do overlap, kinda. HHL has the possibilities ACB and BCA whereas HML has the possibilities ACB, BAC, BCA, CAB, and CBA. So HML contains HHL.
@NathanMerrill I sort it because it fits stars and bars better that way. :P