🧪 We're running a cheminformatics notebook competition!

Enter by October 4
67 / 103
Suguru

Suguru

by marimo team

Interactive Suguru puzzle solver and generator

About this notebook

This notebook solves Suguru puzzles. A Suguru puzzle is a grid split into regions. Each region of size N must hold the numbers 1 to N. No two touching cells may share a value. The notebook builds a puzzle from a 5x5 grid widget. It uses marimo for the interface. It uses pandas for a comparison table. It uses mohtml to draw each board as a colored HTML table.

The reader edits the region shapes with the SuguruGeneratorWidget. The widget runs inside marimo's anywidget wrapper. When the shapes change, the notebook rebuilds the board. It then runs three solvers on the same board. A pandas table shows each solver name, its solved status, and its recursive call count. Below the table, the notebook shows the three final boards next to each other.

All three solvers use backtracking. Each solver picks the empty cell with the fewest possible values. A context manager makes a move and undoes it when a branch fails. The BasicSolver explores every branch. The SmartSolver drops a branch early when a cell has zero possible values. The ConstraintPropSolver first fills every forced cell, then backtracks. A decorator counts the recursive calls and stops after a maximum. The default maximum is 100000 calls.

Related notebooks