Slitherlink

site: slitherlink.lucas.mat.br source on GitHub updated

A toolkit for the classic Slitherlink puzzle (also known as Loop the Loop or Fences) — draw a single closed loop along grid edges so that every numbered cell has exactly that many of its four sides on the loop. Unique solution, reachable by logic alone.

Two implementations sharing the same ideas. A Python library (NumPy, NetworkX, OpenCV, optional OR-Tools) with a constructive generator, constraint-propagation solver, clue-reduction strategies, and image/video rendering. And a browser version in vanilla JS — a static, dependency-free SPA with the entire engine ported plus an interactive board.

The theory behind it. A loop is the boundary of a region (Jordan curve theorem); uniqueness is monotonic under clue removal. Generation uses constructive region growth with invariants — no rejection sampling. The solver combines constraint propagation with backtracking, union-find for single-loop detection, and an optional OR-Tools CP-SAT oracle for large boards. Clue reduction offers multiple strategies (greedy, binary search, CEGAR) trading speed against minimality.