The Mathematics Behind How Far Can You Climb?

What looks like a simple number puzzle turns out to be a window into some surprisingly deep mathematical ideas.


You start at 1. Move to a neighbouring square with a higher number. How long a path can you make?

Simple enough to explain in ten seconds. Hard enough that you’ll find yourself staring at the grid five minutes later, convinced you’ve nearly cracked it. That tension — between how easy a problem is to understand and how tricky it is to solve — is at the heart of some fascinating mathematics.

Let’s explore what’s really going on under the hood.


The Grid as a Graph

If you’ve taught Decision Maths or Further Maths, you’ll recognise what’s about to happen: we’re going to turn the grid into a graph.

Every cell becomes a vertex (or node). Two cells are connected by an arrow — a directed edge — if they’re next to each other horizontally or vertically, and one has a strictly higher value than the other. The arrow points from the lower value to the higher.

Here’s the key observation: you can never go backwards. Once you’ve moved from a cell with value 10 to a cell with value 15, you’re done with 10 — there’s no way back, because 15 is higher than 10. In fact, you can never revisit any cell you’ve already left.

This means the graph structure has no loops. In graph theory language, we have a directed tree — a connected graph where all the edges point “one way” and there are no cycles.

Why this matters: The moment you notice the grid forms a directed tree, certain mathematical techniques become available that wouldn’t work on a general graph.

Finding the Longest Path

Your goal is to find the longest path — the sequence of moves that visits the most cells.

For most types of graphs, finding the longest path is extremely difficult. In fact, it’s one of those problems where the only known approach is to check essentially every possibility, which quickly becomes impossibly slow as the grid gets bigger.

But directed trees are special. There’s a clever algorithm that can find the longest path in linear time — that is, the time it takes grows proportionally with the number of cells, not exponentially.

The technique is called dynamic programming, and it’s one of the key algorithmic ideas in the A-level Further Maths specification.

The Cell Values Are Already Doing the Work

Here’s something elegant: in most graph problems, you’d need to work out the order to process vertices. But in Climb, the cell values themselves tell you the order.

Because you can only move to strictly higher numbers, if you process the cells in order of their values (highest to lowest), you’re guaranteed that when you look at a cell, all the cells you could possibly reach from it have already been processed.

This ordering property is what makes the dynamic programming algorithm work. It’s sitting there in plain sight — the puzzle’s own numbers are doing the heavy lifting.

How the Algorithm Works

The algorithm works backwards from the dead ends.

For each cell, ask: “What’s the longest path I can make starting from here?”

If the cell is a dead end (no valid moves), the answer is just 1 — you’re already there, that’s it.

If the cell has valid moves to other cells, the answer is:
1 + (the longest path from the best onward cell)

You work through every cell this way, starting from the highest values and working down to 1. When you get to cell 1, you know the answer to “what’s the longest path from here?” — and that’s the answer to the whole puzzle.

On a 10×10 grid, this algorithm runs in milliseconds. The computer solves instantly what takes a human several minutes to even attempt.

This is dynamic programming in action: breaking a big problem into smaller sub-problems, solving each one once, and building up to the final answer.

Why Is the Game Hard for Humans?

Here is a subtle point worth sitting with: the computer can solve Climb instantly. A human typically cannot. Why?

The algorithm requires processing vertices in reverse topological order — starting from the dead ends and working backwards. Humans naturally want to move forwards — starting from 1 and following promising-looking chains. These are opposite directions.

When you walk the grid from the start, you are doing a kind of greedy search: at each step, you choose the locally appealing next move. Greedy search is fast and intuitive but it is famously bad at finding globally optimal solutions. You can walk yourself into a dead end after 12 steps when the optimal path has 35.

The “I Give Up” reveal often produces a collective gasp precisely because the optimal path snakes back across the grid in ways that feel almost perverse — it deliberately avoids appealing-looking early moves to preserve longer chains later.

This is the myopia problem in combinatorial optimisation, and it appears everywhere: in financial decisions, in route planning, in scheduling, in machine learning. Climb gives you a visceral experience of it.

Could You Ever Visit Every Cell?

A natural question: could a grid exist where the optimal path visits every single cell?

In graph theory, a path that visits every vertex exactly once is called a Hamiltonian path (named after the Irish mathematician William Rowan Hamilton).

For the 3×3 puzzle at the end of this article, the answer is yes — you can construct an assignment where all 9 cells are visited. But as grids get larger, Hamiltonian paths become increasingly rare.

What’s fascinating is that finding the longest path on a directed tree is computationally easy (as we’ve seen), but deciding whether a Hamiltonian path exists on a general graph is one of the hardest types of problems in computer science — there’s no known efficient algorithm for it.

The puzzle sits right on the boundary between what computers find easy and what they find impossibly hard.

How Many Paths Are There?

Here’s another interesting question: starting from cell 1, how many different valid paths exist (not just the longest one)?

The answer on a typical 8×8 grid is enormous — easily millions or even billions of distinct paths you could take.

This is why the puzzle never feels “solved” even when you know the target score. The search space is vast. There are countless wrong turns you could take, and only one (or a few) that achieve the maximum.

This combinatorial explosion — where the number of possibilities grows explosively with the size of the problem — is a recurring theme across mathematics and computer science.

How the Puzzles Are Built

For those curious about the construction, here’s how each new grid is generated:

Step 1: The entire grid is divided into several long, non-overlapping snaking paths that together cover every cell. Think of it like drawing several snakes across the grid that don’t cross each other.

Step 2: The longest snake becomes the answer path. The others become decoys.

Step 3: Numbers are assigned. The answer path gets 1 at the start, then increases by 3–7 at each step. Each decoy path is carefully positioned so it looks tempting — its values are just above where it branches off — but it always dead-ends before the answer path does.

This is the key: decoy paths are anchored to the answer path at specific branch points. At each branch, the decoy’s first value sits in the gap between “the value where you branch” and “the next value on the correct path.” This makes it reachable but ultimately a dead end.

The result is a grid where wrong paths look entirely plausible, but are provably shorter — not by trial and error, but by mathematical design.


The Algorithm Explained (for Teachers)

If you’re teaching Decision Maths or algorithms, here’s what’s happening under the hood in A-level language:

Phase 1: Partition the Grid (Greedy Algorithm)

The generator uses a greedy algorithm to partition the grid into non-overlapping paths:

PROCEDURE snakeWalk(startCell, visitedCells)
    path ← [startCell]
    ADD startCell TO visitedCells
    current ← startCell
    
    WHILE there exist unvisited neighbours of current DO
        candidates ← unvisited neighbours of current
        
        // Prefer cells that still have onward moves available
        preferred ← cells in candidates that have unvisited neighbours
        
        IF preferred is not empty THEN
            next ← random cell from preferred
        ELSE
            next ← random cell from candidates
        END IF
        
        ADD next TO path
        ADD next TO visitedCells
        current ← next
    END WHILE
    
    RETURN path
END PROCEDURE

This runs until every cell has been visited exactly once. The result is a partition of the grid — several snakes that together cover everything with no overlap.

The “preferred” step is crucial: by favouring cells that still have onward neighbours, the snake tends to stay long rather than cornering itself early. This is a heuristic — a rule of thumb that improves results without guaranteeing optimality.

Phase 2: Value Assignment (Constraint Satisfaction)

Once the snakes are built, values are assigned with specific constraints:

For the answer path (starting at cell 1):

grid[answerPath[0]] ← 1

FOR i ← 1 TO length(answerPath) - 1 DO
    grid[answerPath[i]] ← grid[answerPath[i-1]] + random(12, 19)
END FOR

Notice the large gaps (12–19) between consecutive correct steps. This is deliberate: it creates space for tempting decoy values.

For each decoy path:

// Find where this decoy connects to the answer path
branchPoint ← answer path cell adjacent to decoy
branchValue ← grid[branchPoint]

// Start the decoy just above the branch point
decoyStart ← branchValue + random(1, 3)

// Then fill the rest with small increments
FOR each subsequent cell in decoy DO
    value ← previousValue + random(1, 4)
END FOR

The constraint being satisfied: at every point along the answer path, any available decoy branch must have a starting value that is:

  1. Greater than the branch point (so it’s reachable)
  2. Less than the next correct answer-path value (so following it is wrong)

Because answer-path gaps are 12–19 and decoy increments are 1–4, the decoy runs out of room well before the answer path does.

Phase 3: Finding the Optimal Path (Dynamic Programming with Memoisation)

After generation, the algorithm verifies the longest path using dynamic programming:

PROCEDURE findLongestPath(startCell)
    IF memo[startCell] already exists THEN
        RETURN memo[startCell]
    END IF
    
    validMoves ← neighbours of startCell with higher values
    
    IF validMoves is empty THEN
        RETURN [startCell]  // Base case: dead end
    END IF
    
    longestSubPath ← empty
    FOR each nextCell in validMoves DO
        subPath ← findLongestPath(nextCell)  // Recursive call
        IF length(subPath) > length(longestSubPath) THEN
            longestSubPath ← subPath
        END IF
    END FOR
    
    result ← [startCell] + longestSubPath
    memo[startCell] ← result  // Store for future use
    RETURN result
END PROCEDURE

This is recursive with memoisation — results are cached so each cell is processed once. The recursion terminates because the graph has no cycles (values always increase).

Time complexity: Each of the N cells is visited once, and each visit checks at most 4 neighbours, giving O(N) — linear time.

Phase 4: Difficulty Assessment (Depth-First Search)

The generator also scores puzzle difficulty by measuring how deep the decoy traps are:

PROCEDURE calculateTrapDepth(trapStart)
    maxDepth ← 0
    
    FOR each neighbour of trapStart with higher value DO
        IF neighbour is not on the optimal path THEN
            depth ← 1 + calculateTrapDepth(neighbour)  // Recursive
            maxDepth ← MAX(maxDepth, depth)
        END IF
    END FOR
    
    RETURN 1 + maxDepth
END PROCEDURE

For each step on the optimal path, the algorithm checks: “How many wrong moves could a player take here before hitting a dead end?”

Scoring rule:

  • Trap depth 1: +1 point (shallow trap — easy to recover from)
  • Trap depth ≥2: +3 × depth points (deep trap — a serious detour)

The total difficulty score influences whether the puzzle is accepted or regenerated.

Algorithm Summary

The full generation process combines:

  1. Greedy search (snake-walking)
  2. Constraint satisfaction (value assignment)
  3. Dynamic programming (verification)
  4. Depth-first search (difficulty scoring)

These are all core A-level Further Maths / Decision Maths topics, implemented in a context students can actually see and play.


Links to A-Level and Further Mathematics

If you’re looking for real-world applications of spec content, Climb touches several areas:

Graph Theory (Further Maths / Decision Maths): Directed graphs, trees, and path-finding are core topics. The puzzle provides a concrete, visual instance of these abstract ideas that students can actually play.

Algorithms: Dynamic programming appears in the spec, and the longest-path algorithm is a textbook example of it. The idea of “optimal substructure” — that the best solution to the whole contains best solutions to smaller parts — is exactly what’s happening here.

Proof and Logic: Why can’t you revisit a cell? Because the values form a strictly increasing sequence, and no strictly increasing sequence can loop back on itself. This is the kind of clear logical argument that’s worth writing out carefully in full sentences — great practice for proof-based questions.

Combinatorics: Counting paths through a graph uses the same ideas as counting routes through a street grid or paths through a network — problems students already know from Year 1/AS level.

The puzzle doesn’t just use these ideas — it makes them tangible. When students play it, they’re not just doing graph theory. They’re feeling what graph theory means.


A Puzzle to Try

Here’s something you can explore with just pencil and paper.

Take a 3×3 grid and assign the numbers 1 through 9 to the cells (each number used exactly once). Your goal: arrange them so the longest valid path is as long as possible.

Question 1: Can you achieve a path of length 9 — visiting every single cell?

Question 2: If yes, how many different arrangements achieve this? If no, what’s the maximum length you can achieve, and why?

Question 3: Is there a pattern to the successful arrangements? (Hint: think about a checkerboard colouring of the grid.)

This small problem contains the full depth of everything we’ve discussed: graph structure, Hamiltonian paths, and the interplay between local choices and global results.


Spoiler for Question 1: Yes, it’s possible! Here’s one solution:

1  2  3
6  5  4
7  8  9

The path snakes through: 1→2→3→4→5→6→7→8→9.


The grid in front of you isn’t just a number puzzle. It’s a hands-on introduction to ideas that underpin everything from satellite navigation to supply chain optimisation to DNA sequencing.

How Far Can You Climb? is available to play at m4th5.co.uk. Every grid is generated fresh — each one a unique mathematical structure, solved instantly by an algorithm but still genuinely challenging for human minds.