Calculate permutation with Pattern constraints in 2D Grid

I know this is more of a mathematical question, but I guess that we all come across such questions every now and then, so maybe someone can help me on this permutation related question.
Here is a pattern generation method that I have been working on which generates 2D Grid of Letters like this


"bCombo" input is a flexible variable for Letter "B".

The Pattern logic is such that

"Pattern for D: Places 3 Consecutive D per selection"
"Pattern for C: Places 2 Consecutive C per selection"
"Pattern for B: Places {bCombo} Consecutive B selection"
"Pattern for A: Places 1 A per selection"    

as highlighted in the image above.

As per studies so far if you have different objects in a total of ā€œnā€ object the way to calculate the permutation is

    object aCount = x
    object bCount = y
    object cCount = z
   Then the Permutation looks like: n!/(x! * y! * z!)   

the above mentioned permutation is already having a constraint of different objects.
Here are the constraints that I have thought of so far from the image above,

  1. The length of each row.
  2. The total no. of rows.
  3. for each length of row, it should place valid patterns for each letter selected. (The Current code does this)

Based on these questions so far, I have been trying to figure out the how to calculate the permutation.
I hope someone can give inputs on this that could help in progressing the exercise.

Thank you.

Here is the Actual Code so far that creates pattern : 015_GH_Math_2D Permutation.gh (10.5 KB)

See attached and modify accordingly (for your rules/needs).

PermutationsCombinations_EntryLevel_V1.gh (117.0 KB)

BTW: P/C are solved via recursion (meaning: handle with extreme care)