Project Euler Lab - Problem 115

#115 - Counting Block Combinations II

● AppliedOfficial difficulty: 11%CountingTier B - browser, with the efficient algorithmNot viewed
↖ Euler Lab

NOTE: This is a more difficult version of Problem 114.

A row measuring \(n\) units in length has red blocks with a minimum length of \(m\) units placed on it, such that any two red blocks (which are allowed to be different lengths) are separated by at least one black square.

Let the fill-count function, \(F(m, n)\), represent the number of ways that a row can be filled.

For example, \(F(3, 29) = 673135\) and \(F(3, 30) = 1089155\).

That is, for \(m = 3\), it can be seen that \(n = 30\) is the smallest value for which the fill-count function first exceeds one million.

In the same way, for \(m = 10\), it can be verified that \(F(10, 56) = 880711\) and \(F(10, 57) = 1148904\), so \(n = 57\) is the least value for which the fill-count function first exceeds one million.

For \(m = 50\), find the least value of \(n\) for which the fill-count function first exceeds one million.

This problem is taken from Project Euler, Problem 115.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=115. Published Friday, 24th February 2006, 06:00 pm. Solved by 11,443 members at time of mirroring.

Why this is useful

Mathematical Foundation. Exact counting underlies discrete pricing lattices, scenario enumeration, and combinatorial probability (Phase 7).

We classify relevance honestly - not every Euler problem is a trading application.

Learning mode

Pick how much scaffolding you want. Your choice is remembered per problem.

Scratchpad

Mathematical notes, formulas, pseudocode, hypotheses, complexity notes. Saved automatically with your progress.

Python workbench

Tier B - browser, with the efficient algorithm
Runs in the browser only with the intended efficient algorithm; a naive loop will hit the timeout.

Real Python (Pyodide) in a sandboxed Web Worker - no network, no filesystem, no DOM access. Ctrl/Cmd+Enter runs. Escape leaves the editor. Stop terminates the worker.

Python runtime not loaded (it boots on first run - a one-time local load).

Check your answer

Answers are checked against a salted hash held in a separate file - not printed in this page. This prevents accidental spoilers; it is not cryptographic protection (see the build notes).

Progressive hints

Confidence

Low confidence schedules this problem for spaced review, even if you solved it.

Reference solution

Spoiler
The complete original explanation (interpretation, naive approach, insight, proof, complexity, Python implementation, tests, common mistakes, alternatives) is hidden and lazy-loaded. Reveal it only after a meaningful attempt - the struggle is where the learning happens.