The Graph Theory Behind Slitherlink: Loops, Edges & the Inside-Outside Trick

Slitherlink guide ยท 6 min read

Slitherlink looks like a gentle pastime: a few numbers, a single loop, a quiet ten minutes with a pencil. Yet under that calm surface sits a puzzle that mathematicians and computer scientists find genuinely interesting. Its single-loop structure is pure graph theory, it hides a beautiful topological trick that expert solvers use without always knowing its name, and in its general form it is provably hard for computers. This article is a friendly tour of the maths behind Slitherlink, no equations required. Understanding it will not just satisfy your curiosity; it will quietly change how you see the loop. Want to look at a grid while you read? Play a Slitherlink puzzle.

A loop is a cycle in disguise

Start with the loop itself. To a mathematician, the grid of dots at the corners of the cells is a graph: the dots are vertices, and the little line segments between neighbouring dots are edges. A Slitherlink solution is a special set of those edges, and it has a precise graph-theory description.

The finished loop is a single cycle: a closed path that visits a set of vertices and returns to its start, using each vertex it touches exactly once. In graph terms, every dot in the grid ends up with a tidy property. The loop either skips a dot entirely (it touches zero of the edges there) or passes straight through it (it uses exactly two). No dot ever has one line, which would be a loose end, and none has three, which would be a branch. Each vertex has degree 0 or 2, and the used edges form one connected cycle. That single sentence captures the entire goal of the puzzle in the language of graphs.

The inside-outside trick (and the theorem behind it)

Here is the most elegant idea in Slitherlink, and it comes straight from topology. A single closed loop drawn on a flat surface does something guaranteed: it divides everything into an inside and an outside. This is the famous Jordan curve theorem, which says that any simple closed curve splits the plane into exactly two regions, with the curve as the boundary between them.

Apply that to Slitherlink and a powerful tool appears. Every cell of the grid is either inside the final loop or outside it. And the loop is precisely the boundary between the two:

  • Two neighbouring cells on the same side (both inside, or both outside) have no loop edge between them.
  • Two neighbouring cells on opposite sides (one inside, one outside) have a loop edge between them.

So instead of thinking about edges at all, you can think about colouring every cell inside or outside, and the loop falls out automatically as the line between the colours. Expert solvers use exactly this "inside-outside" reasoning to crack hard grids, treating the number clues as constraints on the colouring. For instance, the cells around the outer border are all outside, which gives you a foothold to spread the colouring inward. It is a genuine solving technique and a piece of pure topology at the same time. (For how to put it and the other patterns to work, see our tips and techniques page.)

Why the numbers are really about parity

The inside-outside view also explains what the number clues are doing at a deeper level. A clue counts how many of a cell's four edges are on the loop, which is the same as counting how many of its four neighbours are on the opposite side of the inside-outside divide. A 0 means all four neighbours share the cell's side; a 3 means three of the four are on the other side. The numbers, in other words, are constraints on how the inside-outside regions can fit together around each cell. That is why 0s and 3s are such strong clues: they pin down a cell's entire neighbourhood of the colouring at once.

So how hard is Slitherlink, really?

Now the surprising part. Despite its tiny rulebook, the general Slitherlink problem is NP-complete, a formal way of saying it belongs to a class of famously hard computational problems. It sits in the same complexity company as many other Nikoli-style puzzles that have been proven NP-complete, including generalised Sudoku and Nurikabe.

In plain terms, NP-complete means two things. A finished solution is easy to check (just verify the loop and the clues), but finding a solution for an arbitrary grid is believed to require an amount of work that explodes as the grid grows, with no known shortcut guaranteed to avoid a huge search in the worst case. It is the same paradox that shows up across this puzzle family: dead simple to describe, potentially brutal to solve in general.

Then how do humans finish them?

If the general problem is so hard, how do you close a loop over a cup of tea? For the same two reasons that apply to every NP-complete puzzle. First, the grids you actually play are carefully designed to have a single solution reachable by a clean chain of logic, which spares you the nasty worst case entirely. The hard instances that make Slitherlink NP-complete are pathological monsters, not the elegant puzzles in a book or on this site. Second, NP-completeness is about enormous, worst-case grids; a 10ร—10 puzzle is tiny by computational standards, and the intended logical path, helped along by the inside-outside trick, gets you there without ever fighting the exponential blow-up.

A puzzle worth a second look

That is the quiet wonder of Slitherlink. The same loop you draw for relaxation is a cycle in a graph, a worked example of the Jordan curve theorem, and a member of one of computer science's hardest problem classes, all at once. None of it makes the puzzle harder to enjoy. If anything, knowing that every clue is really a statement about inside and outside makes the next grid a little more beautiful to solve.

So enjoy the maths, then go put it to rest by closing a perfectly fair, perfectly logical loop. Play a Slitherlink puzzle now, or read the rules first.

Frequently asked questions

Is Slitherlink NP-complete?

Yes. Computer scientists have proven that the general Slitherlink problem is NP-complete, placing it among the hardest problems in the class NP, alongside other Nikoli-style puzzles like generalised Sudoku and Nurikabe. This means that, in the worst case, solving an arbitrary Slitherlink grid is computationally very hard, despite the puzzle's simple rules.

What is the inside-outside trick in Slitherlink?

The inside-outside trick treats every cell as either inside or outside the final loop. By the Jordan curve theorem, a single closed loop divides the plane into an inside and an outside, and the loop is exactly the boundary between them. Two neighbouring cells on the same side share no loop edge, while two on opposite sides have a loop edge between them, so colouring cells inside or outside reveals the loop.

How is Slitherlink related to graph theory?

A Slitherlink solution is a single cycle in the graph formed by the grid's dots (vertices) and the segments between them (edges). Every dot ends up with degree 0 or 2 (touched by zero or two loop edges), and the used edges form one connected closed loop. This makes Slitherlink a concrete, playable example of cycles in graph theory.

If Slitherlink is NP-complete, why can I still solve it?

Because the puzzles you play are specially designed to have a single solution reachable by clean logic, which avoids the worst-case difficulty entirely. NP-completeness concerns enormous, worst-case grids, not the small, carefully constructed puzzles in books and apps, which both humans and computers solve readily.