Project Euler Lab - Problem 702

#702 - Jumping Flea

● ResearchOfficial difficulty: 96%NetworksTier C - reduced scale in browser; full scale in notebookNot viewed
↖ Euler Lab

A regular hexagon table of side length \(N\) is divided into equilateral triangles of side length \(1\). The picture below is an illustration of the case \(N = 3\).

hexagonal table

An flea of negligible size is jumping on this table. The flea starts at the centre of the table. Thereafter, at each step, it chooses one of the six corners of the table, and jumps to the mid-point between its current position and the chosen corner.

For every triangle \(T\), we denote by \(J(T)\) the minimum number of jumps required for the flea to reach the interior of \(T\). Landing on an edge or vertex of \(T\) is not sufficient.

For example, \(J(T) = 3\) for the triangle marked with a star in the picture: by jumping from the centre half way towards F, then towards C, then towards E.

Let \(S(N)\) be the sum of \(J(T)\) for all the upper-pointing triangles \(T\) in the upper half of the table. For the case \(N = 3\), these are the triangles painted black in the above picture.

You are given that \(S(3) = 42\), \(S(5) = 126\), \(S(123) = 167178\), and \(S(12345) = 3185041956\).

Find \(S(123456789)\).

This problem is taken from Project Euler, Problem 702.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=702. Published Saturday, 15th February 2020, 07:00 pm. Solved by 189 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 C - reduced scale in browser; full scale in notebook
Browser runs a reduced, clearly-labelled educational scale; the original scale is provided 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.