Skip to content

Repository files navigation

Puzzle Kit

This repository provides 100+ useful, efficient and problem‑specific solvers for a variety of logic puzzles. The underlying solving engine is the open‑source Google OR-Tools CP-SAT solver. For more details of puzzles and their input format, you can refer to docs of puzzlekit.

For simplicity, the dataset is removed to puzzlekit-dataset repo. The structured dataset contains 41k+ instances covering 130+ specific and popular puzzle types (e.g. Nonogram, Slitherlink, Akari, Fillomino, Hitori, Kakuro, Kakuro), mostly from Raetsel's Janko and puzz.link. The details are listed in the table below.

This repo also provides bidirectional conversion between puzz.link and Penpa+ puzzle URLs for supported genres (19 for now) via a shared intermediate representation. puzz.link-like links from common mirrors (e.g., pzplus.tck.mn, pzv.jp) are also accepted.

Table of puzzles, datasets and solvers.

#.P and #.S indicate the number of puzzles and solutions of specific puzzle type respectively.

Max Size shows the maximum scale of collected puzzles.

Sol? shows if the solver has been implemented currently.

Avg T and Max T indicates the average / maximum time required to solve one puzzle grid among all instances (in seconds).

#.V shows the number of verified solutions compared with the expected solutions. Note that some of solutions failed this mainly because of additional yet unpopular constraints (like diagnonal-ABCEndView, which is a bit rare), or different variants of puzzles(like different shapes of 6x6 Jigsaw Sudoku and Bricks puzzle).

No.Puzzle Name#.P#.SMax SizeSol?Avg T(s)Max T(s)#.V
1ABCEndView6076078x80.0140.042591
2Akari970970100x1000.0140.479970
3Aqre909017x170.1222.38790
4Araf12012010x18---
5BalanceLoop707017x170.0620.21870
6Battleship86186030x300.1031.748860
7Binairo38038014x140.0070.015380
8Bosanowa383811x160.0150.17838
9Bricks2102108x80.0040.013190
10Buraitoraito10110015x150.0070.159100
11Burokku27027010x10---
12ButterflySudoku777712x120.0080.01177
13CanalView11011017x170.1201.157110
14CastleWall11011050x500.0581.184110
15Cave41941925x250.21111.318419
16Chocona25025017x17---
17Clueless1Sudoku292927x270.0290.04229
18Clueless2Sudoku404027x270.0350.08340
19CocktailLamp505017x17---
20Cojun12012017x170.0070.073120
21ConsecutiveSudoku2112119x9---
22CountryRoad27027015x150.0290.128270
23Creek44044040x500.38913.115440
24CurvingRoad19019014x14---
25Detour808013x120.0230.18480
26DiffNeighbors14014015x150.0150.027140
27DigitalBattleship808012x12---
28Dominos58258141x420.0061.224580
29Doors27027012x12---
30DoppelBlock2402408x8---
31DotchiLoop606017x170.0380.08960
32DoubleBack10010026x260.0260.241100
33EntryExit17017016x160.0390.095170
34Eulero2902905x50.0040.007290
35EvenOddSudoku1291299x90.0040.005129
36Factors15015011x11---
37Fillomino84084050x64---
38Fobidoshi25025012x120.0560.150250
39Foseruzu31031030x45---
40Fuzuli1601608x80.0100.018160
41Galaxies58058020x36---
42Gappy42942718x180.0190.062427
43Gattai8Sudoku12012021x330.0210.032120
44Geradeweg10010014x140.0500.157100
45GokigenNaname78078024x36---
46GrandTour35035015x150.0200.070350
47Hakoiri14014012x120.0980.263140
48Hakyuu48048030x450.0420.801480
49Hanare10710716x16---
50Hashi91091040x60---
51Heyawake78778731x450.1394.756786
52Hidoku51051010x100.0260.140510
53Hitori94194125x250.0101.017941
54JigsawSudoku6806809x90.0030.007665
55Juosan808030x450.0110.07580
56Kakkuru4004009x90.0030.016389
57Kakurasu28028011x110.0030.005280
58Kakuro99999931x460.0110.200999
59KenKen4304309x90.0050.135430
60KillerSudoku8108109x90.0060.119584
61Koburin15015012x120.0200.041150
62Kuromasu56056031x450.0704.359560
63Kuroshuto21021014x140.1450.806210
64Kurotto23023019x270.85316.754227
65LITS41941040x570.61940.630410
66Linesweeper31031016x160.0170.045310
67Magnetic43943912x120.0100.025439
68Makaro19019015x150.0070.010190
69MarginSudoku1491499x9---
70Masyu83082840x580.0660.790828
71Mathrax1751759x90.0040.014175
73Mejilink108x80.0120.0120
74MidLoop2210x100.0140.0252
75Minesweeper36036014x240.0050.023360
76MoonSun20020030x450.0410.304200
77Mosaic165104118x1000.0150.133104
78Munraito36036012x120.0100.025360
79Nanbaboru2702709x9---
80Nanro15915914x140.1380.406159
81Nawabari16016014x140.0200.039160
82Nondango11011014x140.0040.009110
83Nonogram2338233730x400.3001.4942337
84Norinori28928936x540.0080.082288
85NumberCross1701708x80.0030.006170
86NumberLink58058035x48---
87NumberSnake707010x10---
88Nurikabe1130113050x50---
89Nurimisaki10010010x100.0590.114100
90OneToX585810x100.0110.07558
91PaintArea22622612x120.0642.336226
92Patchwork21121112x120.0200.033211
93Pfeilzahlen36035910x100.0110.021358
94Pills16416310x100.0070.008163
95Pipeline34934920x20---
96Pipelink19019030x45---
97Pipes2260x400.3840.9592
100Putteria606016x160.0250.05660
101RegionalYajilin707010x180.0210.05870
102Rekuto22022014x14---
103Renban1501509x90.0050.059150
104SamuraiSudoku27227221x210.0110.022272
105Shakashaka36936922x30---
106Shikaku50150150x400.0100.078498
107Shimaguni26626630x450.0320.537266
108Shingoki10310341x410.0821.204103
109Shirokuro11011017x170.0060.008110
110ShogunSudoku909021x450.0300.04890
111Shugaku13013030x450.6659.848130
112SimpleLoop707017x180.0200.05670
113Skyscraper4704708x80.0150.077470
114SkyscraperSudoku50509x9---
115Slitherlink1176115260x600.0671.8501149
116Snake23023012x120.0620.216230
117SoheiSudoku12012021x210.0100.014120
118SquareO1208015x150.0040.00780
119Starbattle30930825x250.0090.046308
120Sternenhimmel18818817x17---
121Stitches11011015x150.0050.013110
122Str8t5605609x90.0040.008560
123Sudoku12512516x160.0100.019125
124Suguru20020010x100.0080.013200
125Sukoro14014012x12---
126SumoSudoku11011033x330.0320.046110
127Tatamibari15015014x140.0210.051150
128TennerGrid3753746x100.0070.010374
129Tent70670630x300.0060.026706
130TerraX808017x170.0090.01880
131Thermometer25025010x100.0030.006250
132TilePaint37737716x160.0040.086377
133Trinairo606012x120.0180.04660
134Tripletts19019010x12---
135Usoone13013030x450.0310.430130
136WindmillSudoku15015021x210.0120.034150
137Yajikabe10010017x170.1150.492100
138Yajilin61061039x570.0520.512610
139YinYang17017014x140.3161.897170
140Yonmasu12012010x10---
Total4127041123-----
Supported puzzle types for URL interchange

(canonical IR name, puzz.link token, aliases, Penpa genre tag)

Canonical (IR)puzz.link tokenpuzz.link aliasesPenpa genre tag
aqreaqreaqreaqre
ayeheyaayeheyaayeheyaayeheya (ekawayeh)
castlecastlecastlecastlewall
countrycountrycountrycountry road
hebihebihebi, snakeshebi-ichigo
heyawakeheyawakeheyawake, heyawacky, heyawackheyawake
kurochutekurochutekurochute, kuroshuto, kurochutokurochute
kurodokokurodokokurodokokurodoko
kurottokurottokurottokurotto
masyumasyumasyu, mashu, pearlmasyu
moonsunmoonsunmoonsunmoon or sun
nonogramnonogramnonogramnonogram
nurikabenurikabenurikabenurikabe
nurimisakinurimisakinurimisakinurimisaki
shikakushikakushikakushikaku
shimagunishimagunishimagunishimaguni (islands)
slitherlinkslitherslitherlinkslitherlink
stostonestostonestostonestostone
yajilinyajilinyajilin, yajirinyajilin
Gallery of some puzzles (not complete!)

Related Projects & Online Play

If you are looking for online playing or a browser-based solver with excellent performance, here are some fantastic alternatives:

  • Noqx 🎉, with interactive penpa-edit style web interface: An enhanced and more-efficient logic puzzle solver based on Clingo (Answer Set Program (ASP) solver) and WASM. It supports 170+ puzzle types, covering most of this repo with same or even better efficiency compared with this repo. It's highly recommend to give it a try.
  • nikoli-puzzle-solver (Z3): Another SAT-based solver with interactive penpa-style web page via z3 solver for 100+ puzzle types. It supports more grid format like hex, triangle and more.
  • puzzle_solver for 90+puzzles by Ar-Kareem, also in OR-Tools.
  • Puzzles-Solver in action by newtomsoft, with browser plugins provided.

How Puzzlekit differs:

Puzzlekit is designed as a Python library (WIP... though) for developers and researchers, offering programmatic access, a unified API, and a massive structured dataset for benchmarking.

Usage

Dependencies: Python >= 3.10, e.g.,

conda create -n py310 python=3.10.14

install the solvers via pip:

pip install puzzlekit

Then a quick tour:

importpuzzlekitproblem_str="""10 10- - - - - b - - - -- b - - w - - b - -w - - - - - - - - -- - - - - - - - w -- - - - - b b - b -- w - w w - - - - -- w - - - - - - - -- - - - - - - - - b- - b - - b - - w -- - - - w - - - - -"""res=puzzlekit.solve(problem_str, "masyu")
# res.show() # If you want to visualize it.

The detailed usage of specific logic puzzles can be found in the docs of puzzlekit.

If you want a batch-run, clone the dataset you need via puzzlekit-dataset to ./assets folder in the root. Then run the scripts/benchmark.py like:

python scripts/benchmark.py -p Hidoku 

The script will create ./benchmark_results folder where two files, benchmark_{timestamp}.csv and README_STATS_{puzzle_name}_{timestamp}.md can show you the details.

If you want to run all instances, use:

python scripts/benchmark.py -a

Currently it will take ~30 min to solve all 30k+ instances available.


If you want to try the bi-directional conversion between penpa+ and puzz.link, follow the quick tour:

importpuzzlekit# 1st methodir=puzzlekit.decode("https://puzz.link/p?slither/10/10/g188227cl1dg367bdcg3ddgbhdgd1agbd760dg2cl633661d")
penpa_url=puzzlekit.encode(ir, "penpa")
print(penpa_url)
# get:# https://swaroopg92.github.io/penpa-edit/#m=edit&p=7VdtT9swEP7Or0...# 2nd method (recommend)penpa_url="YOUR_PENPA_URL"# both full URL or `m=edit&p=...` are okaypuzzlink_url=puzzlekit.convert(penpa_url, "puzzlink")
print(puzzlink_url)
# get:# https://puzz.link/p?slither/10/10/b86ag68dg127bg62aldg8dad8bgdl26dg722cg68dg88b3

See also scripts/quick_start.py for a runnable sample.

Roadmap

  • 130+ Puzzle Solvers & 40k+ Dataset.
  • Unified Python API (pip install puzzlekit).
  • Unified Converter: Batch converting internal formats to penpa-edit or puzz.link URLs.
  • Dataset update, remove duplicates.
  • Docs update.

Reference

Aside from links mentioned above, please refer to the following:

Solving Tools:

Dataset and online play:

About

100+ solvers for logic puzzles with ortools, 41k+ datasets for 130+ puzzles, e.g. Nonogram, Slitherlink, Fillomino, Creek, Akari, Yajilin and Sudoku-variants.

Topics

Resources

Stars

34 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages