MathsReadCompetitive mathematics
Algorithmic puzzle · integer answereasy25 min

Constrained tricolor words

Combinatorial Counting

How many length-22 strings over A, B, C have exactly eight A characters, exactly five C characters, and no two consecutive C characters? (The other nine characters are B.)

Solve using mathematics, algorithms, or your own code offline. Submit only the final integer here—no program, expression, graph, or written proof.

Check your answer without signing in. Sign in to save your progress.

Accepted format: a whole number such as 42 or 123456789. No commas, formulas, or source code.

How to approach this problem

First arrange the A and B characters. Then place the C characters into distinct gaps, including the gaps at the two ends. This prevents adjacent Cs without counting their order twice.

Worked example with different values

With two As, one B and one C, there are 3 arrangements of AAB and 4 gaps in each, giving 12 strings.

Apply the same reasoning to the challenge. This example is a separate practice problem.

Learn the technique: Dynamic programming and grid paths

Report a question or explanation issue

Back to problems →