Project Euler Lab - Problem 490

#490 - Jumping Frog

● ResearchOfficial difficulty: 84%CountingTier D - conceptual / notebook executionNot viewed
↖ Euler Lab

There are \(n\) stones in a pond, numbered \(1\) to \(n\). Consecutive stones are spaced one unit apart.

A frog sits on stone \(1\). He wishes to visit each stone exactly once, stopping on stone \(n\). However, he can only jump from one stone to another if they are at most \(3\) units apart. In other words, from stone \(i\), he can reach a stone \(j\) if \(1 \le j \le n\) and \(j\) is in the set \(\{i-3, i-2, i-1, i+1, i+2, i+3\}\).

Let \(f(n)\) be the number of ways he can do this. For example, \(f(6) = 14\), as shown below:
\(1 \to 2 \to 3 \to 4 \to 5 \to 6\)
\(1 \to 2 \to 3 \to 5 \to 4 \to 6\)
\(1 \to 2 \to 4 \to 3 \to 5 \to 6\)
\(1 \to 2 \to 4 \to 5 \to 3 \to 6\)
\(1 \to 2 \to 5 \to 3 \to 4 \to 6\)
\(1 \to 2 \to 5 \to 4 \to 3 \to 6\)
\(1 \to 3 \to 2 \to 4 \to 5 \to 6\)
\(1 \to 3 \to 2 \to 5 \to 4 \to 6\)
\(1 \to 3 \to 4 \to 2 \to 5 \to 6\)
\(1 \to 3 \to 5 \to 2 \to 4 \to 6\)
\(1 \to 4 \to 2 \to 3 \to 5 \to 6\)
\(1 \to 4 \to 2 \to 5 \to 3 \to 6\)
\(1 \to 4 \to 3 \to 2 \to 5 \to 6\)
\(1 \to 4 \to 5 \to 2 \to 3 \to 6\)

Other examples are \(f(10) = 254\) and \(f(40) = 1439682432976\).

Let \(S(L) = \sum f(n)^3\) for \(1 \le n \le L\).
Examples:
\(S(10) = 18230635\)
\(S(20) = 104207881192114219\)
\(S(1\,000) \bmod 10^9 = 225031475\)
\(S(1\,000\,000) \bmod 10^9 = 363486179\)

Find \(S(10^{14}) \bmod 10^9\).

This problem is taken from Project Euler, Problem 490.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=490. Published Sunday, 23rd November 2014, 07:00 am. Solved by 387 members at time of mirroring.

Why this is useful

Algorithmic Development. Graph/state-space search transfers to routing, dependency resolution, and execution-path optimisation (Phases 16, 17).

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 D - conceptual / notebook execution
Too heavy for browser Pyodide at original scale: the browser is used for planning, small cases and reasoning; full scale runs in a local notebook.

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.