Skip to the game
ArrowsGame
EN

Explainer

Are arrow puzzles mathematically hard?

On this page
  1. What "hard" means to a mathematician
  2. Every arrow board is a waits-for graph
  3. Solvable exactly when there is no loop
  4. Why a wrong order can never trap you
  5. Layers are the longest chain
  6. How fast a computer solves a board
  7. Counting the ways to win is the hard part
  8. Why it still feels hard to people
  9. What would make arrow puzzles truly hard
  10. Questions and answers

Puzzle fans like to ask whether a game is "NP-hard", the way chess fans ask about ratings. For arrow puzzles we could answer with more than an opinion, because the site ships its own solver. We turned each of our 608 plain 2D levels (the ones with no special pieces) into a graph of which arrow waits for which, checked that graph against the solver on every board, counted the exact number of winning orders on 120 small boards, deliberately broke boards 28,100 times by turning arrows round, and timed the solver over all 3,000 levels of both games. This guide explains what we found in plain words, with no formulas, and sets it beside the published proofs about Rush Hour, sliding blocks and other famous puzzles for comparison.

The short version

For a computer, no: an arrow board can be solved in a fraction of a second, because it is solvable exactly when its waits-for graph has no loop, and then any free arrow is a safe move. Counting all the ways to win is the hard part. For a person, the difficulty is finding the next free arrow on a crowded board with three lives.

#What "hard" means to a mathematician

To a mathematician, "hard" is not about how long one board takes you. It is about how the work grows as boards get bigger. A puzzle is easy in this sense if some method solves any board in time that grows like a power of its size (the class called P). It is hard if every known method can blow up exponentially, which is what NP-complete and PSPACE-complete problems are believed to do.

Many famous puzzles have been placed in those classes. A survey of NP-complete puzzles collects dozens of them (Kendall, Parkes and Spoerer, 2008), and the sliding-block family sits even higher:

  • Rush Hour (slide cars until one car can drive out) was shown PSPACE-complete by Flake and Baum in 2002.
  • Sliding blocks in general, even when every block is a 1 × 2 domino, belong to the same class, as Hearn and Demaine showed in 2005.
  • Sokoban, pushing crates onto targets, is PSPACE-complete too.
  • Generalised Sudoku is NP-complete, and so is deciding whether a Minesweeper position is consistent: a finished answer is easy to check, finding one is believed to be hard.

Arrow puzzles look like cousins of these. They are not, and the reason is one rule. Everything below follows from it.

Try it: level 82723 arrows · 3 free at the start

#Every arrow board is a waits-for graph

Pick any arrow and trace the path ahead of its head, cell by cell, to the edge of the board. Every other arrow with a cell on that line must leave first. Draw a dot for each arrow and a link from it to each arrow it waits for, and you have the board's waits-for graph. On our 608 plain levels that graph has 28,100 dots and 106,116 links, 3.78 per arrow. Only 26,471 of the links point at the first arrow on a line, the one you can actually see blocking; the rest wait further down the line.

Level 4 shows the idea in miniature. Its graph is a short stem with a fan at the end:

  1. The 12-cell arrow at column 1, row 1 points up and waits for nothing.
  2. The 7-cell arrow at column 5, row 1 points left and waits for arrow 1.
  3. The 33-cell arrow at column 5, row 2 points up and waits for arrow 2.
  4. The other four arrows each wait for arrow 3, and for nothing else.
Level 4, 8 × 10 board, 7 arrows numbered in a winning order
Figure 1Level 4 numbered in a winning order: arrow 1 waits for nothing, 2 for 1, 3 for 2, and arrows 4 to 7 wait only for arrow 3. Play level 4

The picture is the whole puzzle. Once you know the graph, you know every legal move at every moment: an arrow can leave when everything it waits for has gone.

#Solvable exactly when there is no loop

When can a board be cleared? Exactly when its waits-for graph has no loop. In the language of graph theory, the graph must be a directed acyclic graph. The argument fits in three steps:

  1. If there is a loop (A waits for B, B waits for C, C waits for A), no arrow in it can ever be the first of the three to go, so the board is stuck. Two arrows pointing at each other are the smallest loop.
  2. If there is no loop, at least one arrow waits for nothing. Follow links from any arrow; with no loop you can't go round forever, so you reach an arrow with no links out, and it can leave now.
  3. Removing that arrow leaves a smaller board whose graph still has no loop, so step 2 applies again, until the board is empty.

Those steps are an algorithm, and an old one: Kahn described it in 1962 for scheduling jobs that depend on each other. Its output is a topological order, a list in which everything comes after what it depends on. A winning sequence of taps in our game is precisely a topological order of the waits-for graph.

We checked this on real boards rather than trusting the argument. On all 608 plain levels, a from-scratch graph solver and the site's solver agree on every board (608 of 608).

#Why a wrong order can never trap you

Here is the rule that sets arrow puzzles apart from Rush Hour. When an arrow leaves, it only removes cells. It never moves into a new place, so it can never block a line that was clear. An arrow that is free stays free until you send it. That means any free arrow is a safe move: whatever order you pick, the board can still be finished.

In a sliding puzzle the opposite is true. Moving a car to free one lane fills another, so a move can make the position worse, and a solver may have to explore long detours and undo them. That is where PSPACE-hardness comes from. An arrow board has no detours. Mathematicians call a structure with this "free stays free" property an antimatroid, and on such structures a greedy choice can never paint you into a corner.

Our special pieces were designed to keep the property. A bomb takes extra arrows with it, a one-way gate opens for good once an arrow crosses it, ice thaws when a neighbour leaves, and locks open when the key arrow goes: each of them only ever adds freedom. The game's hint button relies on it. When we played every level by hints alone, 46,355 hints cleared all 1,000 boards without a single bump. The mistakes guide covers the one thing order can cost you, which is lives, not the level.

#Layers are the longest chain

If the order doesn't matter for winning, what makes one board longer than another? The longest chain in its graph. Send every free arrow, then every arrow that became free, and so on; the number of rounds is the number of arrows on the longest waits-for chain. The site calls these rounds layers, and our difficulty labels are built on them.

That is again a theorem you can check. On every one of the 608 plain levels, the longest chain found by a separate depth-first search equals the solver's layer count (608 of 608). The board with the most links is level 701: 1,478 links among 203 arrows, 36 layers.

Level 827, 23 × 19 board, 23 arrows, at the start and after layers 3, 8 and 12
Figure 2Level 827 peeling: 3 arrows can go at the start, and from layer 5 each round frees a single arrow, 11 rounds in a row. Play level 827

Long chains with nothing beside them are what make a board feel like a corridor. Level 827 has only 23 arrows but 15 layers, and from layer 5 on, 11 rounds in a row hold one arrow each: its graph is almost a single line. The record, a run of 16, is on level 287. Why move order matters walks through boards like it from the player's side.

#How fast a computer solves a board

How fast is "easy"? Building the graph means walking each arrow's line once, so the work grows with the number of arrows times the width of the board. Sorting it is proportional to the number of links. Both are small powers of the board size, which puts arrow puzzles in P, the easy class.

In practice, on the Mac that builds this site, the solver that ships with the game cleared all 1,000 2D levels in under a quarter of a second and all 2,000 cube levels in about 2 seconds, playing every tap for real, pieces included. The graph method alone handled the 608 plain levels in 21 milliseconds. The slowest single 2D board took 3 milliseconds. Those are rough timings, not a benchmark, but the gap to Rush Hour is not subtle: for PSPACE-complete puzzles, every known method needs time that can double and double again as the board grows.

This is also why we can promise every level is solvable. Each board was built backwards from a solution by our generator (how the levels are made), then solved again by this independent code before it shipped.

#Counting the ways to win is the hard part

Deciding is easy. Counting is not. How many different tap orders clear a board without a single bump? That is the number of topological orders of its graph (mathematicians say linear extensions), and Brightwell and Winkler proved in 1991 that counting them exactly is #P-complete, a class believed to be even harder than NP. No known method counts them quickly for large boards.

For small boards a computer can still count by brute force over every set of arrows that might be gone. We did that for every plain level of up to 22 arrows:

Bump-free tap orders, counted exactly by the site solver
LevelArrowsLayersFree at startWinning ordersAll possible orders
14142424
2422824
3432424
4741245,040
316118266about 39.9 million
2721292105about 479 million
2521272392about 479 million
2321392936about 6.2 billion
521105about 1.1 billionabout 51.1 quintillion
4102072about 145.7 billionabout 2.4 quintillion

Level 5 has about 1.1 billion winning orders. That sounds like plenty until you compare it with the number of ways to put 21 arrows in a row: about 51.1 quintillion. Tap level 5 in a random order and the chance of never bumping is about one in 47 billion. Level 4 is the opposite extreme: three forced taps, then any order for the last four, so 4 × 3 × 2 × 1 = 24 ways to win.

The count says something about feel. Many winning orders means many arrows free at once, a forgiving board. Few means long chains. But the count grows so fast that even a 20-arrow board like level 410 has about 145.7 billion of them, so for real boards we use layers, which a computer finds instantly.

#Why it still feels hard to people

If the puzzle is easy for a computer, why do people get stuck? Because the computer sees the whole graph at once and you have to build it in your head, one line at a time:

  • Lines are long and boards are big. The biggest board, level 701, has 203 arrows. Checking whether one arrow is free means scanning its whole line, and a clear-looking line can end in an arrow dozens of cells away.
  • Most waits are invisible. Only 25% of the links in our graphs point at the first arrow on a line. The rest are hidden behind it.
  • Bumps cost lives. A computer can try an arrow for free. You have three lives, so a wrong guess has a price even though it never ruins the board.
  • Memory is short. Holding a long chain in mind while you trace it is real work, and after a few links attention slips back to the arrow you started from.

That is a common pattern: a problem that is easy in theory can still be hard to do by eye. Our method for hard levels is really a way of building the graph in your head: count the free arrows, clear a whole layer, and trace stuck arrows back along their chains.

#What would make arrow puzzles truly hard

Small rule changes would turn arrow puzzles into the hard kind. If arrows could slide part of the way and stop, they would fill new cells, and a move could block a line that was open, as in Rush Hour. If arrows could come back onto the board, or if you had to clear the board in the fewest possible taps on a board where taps can be wasted, the safe-move property would go too. Without it a solver may need long detours, and detours are exactly what the sliding-block proofs build their hard boards from.

There is also a place where the hard part hides inside our game: making boards. A board filled with randomly pointed arrows is almost never solvable. We tried it on our own levels, 50 random versions of each: boards of 31 to 60 arrows cleared 17 times in 17,550 tries, and boards above 60 arrows 1 time in 6,500. The generator avoids this by building each board backwards from its solution, which is why every level on this site can be finished.

So the honest answer is: arrow puzzles are easy for machines, interesting for people, and only as hard as the board in front of you. Try level 827 to feel a long chain, or start fresh in unlimited mode.

#Questions and answers

Are arrow puzzles NP-hard?

No, not in the standard rules. A board can be cleared exactly when its waits-for graph has no loop, and a computer finds a winning order in time that grows only polynomially with the board, using a topological sort. Counting all the winning orders is the part that is hard.

Can you get stuck in an arrow puzzle by tapping in the wrong order?

Not in our game. An exit only clears cells, so a free arrow stays free and every order of free taps still leads to a clear board. A wrong tap on a blocked arrow costs a life, but it never makes the level unsolvable.

Is there an arrow puzzle solver?

Yes, one ships with this site: it is what the hint button and the level pages use. It cleared all 1,000 2D levels in under a quarter of a second on our build machine. The hint picks the free arrow that opens the most other arrows.

Play the game

A new daily board every day, over 1,000 levels and the 3D arrow cube, free in your browser.

#Sources