Project Euler Lab - Problem 664

#664 - An Infinite Game

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

Peter is playing a solitaire game on an infinite checkerboard, each square of which can hold an unlimited number of tokens.

Each move of the game consists of the following steps:

  1. Choose one token \(T\) to move. This may be any token on the board, as long as not all of its four adjacent squares are empty.
  2. Select and discard one token \(D\) from a square adjacent to that of \(T\).
  3. Move \(T\) to any one of its four adjacent squares (even if that square is already occupied).
Allowed moves

The board is marked with a line called the dividing line. Initially, every square to the left of the dividing line contains a token, and every square to the right of the dividing line is empty:

Initial setup

Peter's goal is to get a token as far as possible to the right in a finite number of moves. However, he quickly finds out that, even with his infinite supply of tokens, he cannot move a token more than four squares beyond the dividing line.

Peter then considers starting configurations with larger supplies of tokens: each square in the \(d\)th column to the left of the dividing line starts with \(d^n\) tokens instead of \(1\). This is illustrated below for \(n=1\):

Initial setup n=1

Let \(F(n)\) be the maximum number of squares Peter can move a token beyond the dividing line. For example, \(F(0)=4\). You are also given that \(F(1)=6\), \(F(2)=9\), \(F(3)=13\), \(F(11)=58\) and \(F(123)=1173\).

Find \(F(1234567)\).

This problem is taken from Project Euler, Problem 664.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=664. Published Sunday, 7th April 2019, 07:00 am. Solved by 235 members at time of mirroring.

Why this is useful

Algorithmic Development. Optimal substructure and state-space reasoning are exactly how American-option pricing and optimal execution are solved (Phases 13, 16).

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.