Project Euler Lab - Problem 707

#707 - Lights Out

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

Consider a \(w\times h\) grid. A cell is either ON or OFF. When a cell is selected, that cell and all cells connected to that cell by an edge are toggled on-off, off-on. See the diagram for the 3 cases of selecting a corner cell, an edge cell or central cell in a grid that has all cells on (white).

LightsOut

The goal is to get every cell to be off simultaneously. This is not possible for all starting states. A state is solvable if, by a process of selecting cells, the goal can be achieved.

Let \(F(w,h)\) be the number of solvable states for a \(w\times h\) grid. You are given \(F(1,2)=2\), \(F(3,3) = 512\), \(F(4,4) = 4096\) and \(F(7,11) \equiv 270016253 \pmod{1\,000\,000\,007}\).

Let \(f_1=f_2 = 1\) and \(f_n=f_{n-1}+f_{n-2}, n \ge 3\) be the Fibonacci sequence and define \[ S(w,n) = \sum_{k=1}^n F(w,f_k)\] You are given \(S(3,3) = 32\), \(S(4,5) = 1052960\) and \(S(5,7) \equiv 346547294 \pmod{1\,000\,000\,007}\).

Find \(S(199,199)\). Give your answer modulo \(1\,000\,000\,007\).

This problem is taken from Project Euler, Problem 707.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=707. Published Sunday, 22nd March 2020, 10:00 am. Solved by 282 members at time of mirroring.

Why this is useful

Numerical Computing. Matrix methods and linear-recurrence acceleration are the machinery behind covariance work, PCA, and lattice/transition models (Phases 4, 5, 8).

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.