Puzzle PicnicBlog

Order Is the Puzzle: Thinking in Dependencies in Lines

How to see which line blocks which in an arrow puzzle, why any free line is safe, what a topological order is, and why a circle of blockers means a stuck board.

In Lines, the puzzle is the order. A line can leave only when every line in the straight path in front of its arrow has left first, so each line depends on the lines in its way. Solving means finding an order that respects all of those dependencies. Any line whose path is already clear is safe to take, many different orders work, and a board only gets truly stuck if lines block each other in a circle, which Lines never builds.

This post is for players who know how to play Lines and want a clearer way to think about bigger boards. It uses one small example throughout and needs no maths beyond counting.

What "this line blocks that one" means in Lines

In Lines, a line is blocked by every other line that has a square anywhere on the straight path from its arrow to the edge of the board. That path is the line's lane. Three details are worth getting exactly right.

  • The whole lane counts, not just the next square. If two lines cross a lane, both have to go before the line can leave.
  • Only the lane in front of the head matters. A line can bend and cover many squares, but when it leaves, its body follows its head out along the lane. Where the body lies does not affect whether this line can go.
  • The body matters to other lines. Every square a line covers can sit in someone else's lane. A long, bending line can block many others while needing only one clear lane itself.

So each line has a short list of lines it is waiting for. That list is its set of dependencies.

Writing the dependencies down

The clearest way to see the order in a Lines board is to write down, for each line, which lines stand in its lane. Here is a small board to practise on.

A 5 by 5 board with eight lines, A to H. Each letter marks a square of that line; the square with an arrow is the head (> right, < left, ^ up). Lines E, F and G bend. Every square is covered, as in a real puzzle, but the board is far smaller than any level in the app.

Rows are numbered 1 to 5 from the top and columns 1 to 5 from the left. Follow each arrow to the edge and note who is in the way:

LineHead and arrowLane (squares to the edge)Waits for
Arow 3 column 4, rightrow 3 column 5F
Brow 1 column 4, rightrow 1 column 5C
Crow 1 column 5, upnonenothing
Drow 2 column 4, rightrow 2 column 5C
Erow 4 column 3, upcolumn 3, rows 3, 2 and 1A, D and B
Frow 3 column 5, upcolumn 5, rows 2 and 1C
Grow 4 column 2, rightrow 4, columns 3, 4 and 5E and F
Hrow 5 column 1, leftnonenothing

Two lines wait for nothing: C, which points up off the top edge, and H, which points left off the side. Those are your first moves. Everything else waits, directly or through a chain, on C.

Waves: clearing a board one layer at a time

A useful way to read a dependency table is in waves: the lines that are free now, then the lines that become free once those have gone, and so on. On the example board there are five waves.

WaveLines that can goWhy they are free now
1C, HNothing in their lanes
2B, D, FC was the only line in their way
3AF has gone
4EA, D and B have all gone
5GE and F have both gone

H could go in any wave; it waits for nothing and nothing waits for it.

The number of waves equals the longest chain of lines that must leave one after another. Here that chain is C, then F, then A, then E, then G: five lines. Research on sudoku difficulty offers a useful comparison. In a study of more than 1,700 sudoku puzzles and hundreds of solvers, Radek Pelánek found two sources of difficulty: how complex each single step is, and the structure of dependency among the steps (Pelánek, Difficulty Rating of Sudoku Puzzles, 2014). Lines has almost no hard single steps, since each check is "is this lane clear?", so its difficulty comes mostly from the second source: how long and tangled the chains are. On the app's harder levels, the app deliberately places more lines in each other's lanes, so more lines wait on each other.

Topological order, explained gently

An order that never takes a line before the lines it waits for is called a topological order. The term comes from graph theory, where the formal definition is a list of items in which, for every "this must come before that" link, the first item really does come first (Wikipedia: Topological sorting).

You use topological orders every day without the name. Socks go on before shoes. A recipe has you melt the butter before you fold it into the batter. A university course may require another one first. In each case some steps have to wait for others, and many steps do not care about each other at all.

The standard method for finding such an order was published by A. B. Kahn in 1962, in a paper called "Topological sorting of large networks" in Communications of the ACM (Wikipedia: Topological sorting). In plain words it goes like this:

  1. Find every item that waits for nothing.
  2. Take one of them and put it next in your list.
  3. Cross it off every other item's waiting list.
  4. Repeat until nothing is left.

That is exactly how you play Lines. Find a free line, tap it, notice which lines it was blocking, and look again. You have been running Kahn's method all along.

There are many correct orders. A topological order is rarely unique. The example board above can be cleared in 96 different orders. Every one of them starts with C or H and puts F before A. Leaving H aside, E and G are always the last two, E first. H can go anywhere. Inside those rules you can do as you like.

Why any free line is a safe move

In Lines, taking a free line can never make another line harder to free. Lines only ever leave the board; nothing ever moves into a lane. So the list of lines a given line is waiting for can only get shorter.

That rules out a whole class of mistakes found in other puzzles. In a sliding-block puzzle, a move can box a piece in, and you have to undo it. In Lines, there is no such move. If a line is free, tapping it is never wrong, however early it seems. The only decision that matters is whether a line really is free, and a blocked tap simply counts as a mistake while the line stays where it was.

This also means you never need to plan a whole order in advance. You need only the next free line. The order takes care of itself.

Circles: the only way a board gets stuck

A board of arrow lines is stuck for good only when some lines block each other in a circle. Graph theory states it precisely: a topological order exists if and only if there is no directed cycle (Wikipedia: Topological sorting). In puzzle words, the board can be cleared exactly when no group of lines is waiting on itself.

The simplest circle is two lines pointing at each other:

Two lines on one row, heads facing. A points right and B sits in its lane; B points left and A sits in its lane. Neither can ever leave. Lines never builds a board like this.

A circle can also run through more lines. Here four lines chase each other round a square, like a pinwheel:

Four lines in a pinwheel around an empty centre (> right, v down, < left, ^ up). A waits for B, B waits for C, C waits for D, and D waits for A. No line can go first, so the board can never be cleared.

You will never meet either of these in Lines. The app builds each puzzle backwards: it adds one line at a time and gives each new line a clear way out past every line already placed. Playing those additions in reverse clears the board. A circle cannot form that way: whichever line of a would-be circle was added last needed a clear lane past the others, so it cannot be waiting for them. When the app adjusts lines afterwards to fill the last gaps in the shape, it keeps a change only if the board can still be cleared. So if a board looks stuck, it is not. A free line is there, and you have not spotted it yet.

Reading dependencies backwards when you are stuck

When no free line jumps out, work backwards from any line you would like to clear. This finds a free line quickly, even on a big board.

  1. Pick any line and follow its arrow to the edge.
  2. Find the first line in its way.
  3. Now follow that line's arrow to the edge, and find the first line in its way.
  4. Keep going. Each step lands on a line that sits earlier in the order.
  5. Because there are no circles, the chain must end, and it ends at a line with a clear lane. Tap it.

On the example board, start from G. G's lane runs into E. E's lane runs up column 3 into A. A's lane runs into F. F's lane runs into C, and C's lane is clear. So C is a free line, found in four short hops.

When you tap a blocked line in Lines, the line in its way is outlined in dashed red. That is the first step of this chain, shown for you. A hint goes further and lights up a line that can go now.

Frequently asked questions

Is there only one correct order in Lines?

Almost never. Most boards can be cleared in many orders, because many lines do not depend on each other at all. The small example board in this post has 96 orders that work. What is fixed is the "must go before" rules between particular lines.

Can I make a Lines puzzle impossible by going in the wrong order?

No. Lines only ever leave, so a line that is free stays free whatever you do next. A tap on a blocked line counts as a mistake, but the line stays put and the board is unchanged.

What is a topological sort, in simple words?

It is a way of listing tasks so that every task comes after the tasks it depends on, like putting on socks before shoes. It exists exactly when no group of tasks waits on itself in a circle. Clearing a Lines board, one free line at a time, is a topological sort done by hand.

Why do harder Lines puzzles feel harder if every free line is safe?

Because a smaller share of the lines is free at any moment, and those few are hidden among many more. On harder levels more lines wait on each other, chains of blockers are longer and lines are longer and more tangled, so it takes more looking to find the next line that can go. The tips in solving big Lines puzzles are about exactly that search.

Where to go next

Take a Medium puzzle on the Lines game page and play it in waves: clear every line that is free, then look again at what opened up. When you stall, run the backwards chain from any line. The Lines strategy guide collects the other ways to spot a free line, and arrow puzzles explained covers the wider family of tap-away games. For how the app builds puzzles that always have an answer, see how a puzzle is made from a seed.

Sources