MathsReadCompetitive mathematics
Algorithmic puzzle · integer answermedium50 min

Letters under three rules

Exact Enumeration

Count length-7 strings over A, B, C, D such that A occurs exactly twice, no two Bs are adjacent, and C occurs STRICTLY more often than D.

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

Track letter counts and whether the previous letter was B. Discard invalid transitions early. At the final position, enforce the exact A count and strict comparison between C and D.

Worked example with different values

For a two-letter string with exactly one A and more Cs than Ds, AC and CA qualify. AD fails the strict comparison.

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

Learn the technique: Number theory: divisors, gcd and modular arithmetic

Report a question or explanation issue

Back to problems →