multi-puzzle-solver 0.9.4__py3-none-any.whl → 0.9.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: multi-puzzle-solver
3
- Version: 0.9.4
3
+ Version: 0.9.6
4
4
  Summary: Efficient solvers for numerous popular and esoteric logic puzzles using CP-SAT
5
5
  Author: Ar-Kareem
6
6
  Project-URL: Homepage, https://github.com/Ar-Kareem/puzzle_solver
@@ -237,6 +237,16 @@ These are all the puzzles that are implemented in this repo. <br> Click on any o
237
237
  <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/stitches_solved.png" alt="Stitches" width="140">
238
238
  </a>
239
239
  </td>
240
+ <td align="center">
241
+ <a href="#battleships-puzzle-type-29"><b>Battleships</b><br><br>
242
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/battleships_solved.png" alt="Battleships" width="140">
243
+ </a>
244
+ </td>
245
+ <td align="center">
246
+ <a href="#kakurasu-puzzle-type-30"><b>Kakurasu</b><br><br>
247
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/kakurasu_solved.png" alt="Kakurasu" width="140">
248
+ </a>
249
+ </td>
240
250
  </tr>
241
251
  </table>
242
252
 
@@ -280,6 +290,8 @@ These are all the puzzles that are implemented in this repo. <br> Click on any o
280
290
  - [Thermometers (Puzzle Type #26)](#thermometers-puzzle-type-26)
281
291
  - [Aquarium (Puzzle Type #27)](#aquarium-puzzle-type-27)
282
292
  - [Stitches (Puzzle Type #28)](#stitches-puzzle-type-28)
293
+ - [Battleships (Puzzle Type #29)](#battleships-puzzle-type-29)
294
+ - [Kakurasu (Puzzle Type #30)](#kakurasu-puzzle-type-30)
283
295
  - [Why SAT / CP-SAT?](#why-sat--cp-sat)
284
296
  - [Testing](#testing)
285
297
  - [Contributing](#contributing)
@@ -2320,6 +2332,9 @@ side = np.array([0, 10, 6, 4, 4, 1, 5, 8, 2, 6, 5, 11, 4, 3, 7])
2320
2332
  binst = solver.Board(board=board, top=top, side=side)
2321
2333
  solutions = binst.solve_and_print()
2322
2334
  ```
2335
+
2336
+ Note: `solver.Board` accepts an optional `connection_count=N` parameter to specify the (÷N) stitches puzzle (by default, 1 stitch).
2337
+
2323
2338
  **Script Output**
2324
2339
 
2325
2340
  ```python
@@ -2350,6 +2365,147 @@ Time taken: 0.01 seconds
2350
2365
 
2351
2366
  ---
2352
2367
 
2368
+ ## Battleships (Puzzle Type #29)
2369
+
2370
+ * [**Play online**](https://www.puzzle-battleships.com/)
2371
+
2372
+ * [**Solver Code**][29]
2373
+
2374
+ <details>
2375
+ <summary><strong>Rules</strong></summary>
2376
+
2377
+ - You have to find the location of the battleships hidden in the grid. Some battleships may be partially revealed.
2378
+ - A battleship is a straight line of consecutive black cells.
2379
+ - The number of the battleships from each size is shown in the legend.
2380
+ - 2 battleships cannot touch each other (even diagonally)
2381
+ - The numbers outside the grid show the number of cells occupied by battleships on that row/column.
2382
+
2383
+ </details>
2384
+
2385
+ **Unsolved puzzle**
2386
+
2387
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/battleships_unsolved.png" alt="Battleships unsolved" width="500">
2388
+
2389
+ Code to utilize this package and solve the puzzle:
2390
+
2391
+ ```python
2392
+ from puzzle_solver import battleships_solver as solver
2393
+ board = np.array([
2394
+ [' ', ' ', ' ', ' ', ' ', 'S', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
2395
+ [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'S', ' ', ' ', ' ', ' '],
2396
+ [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'O', ' ', ' '],
2397
+ [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
2398
+ [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
2399
+ ['W', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
2400
+ [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
2401
+ [' ', ' ', ' ', ' ', ' ', ' ', 'O', ' ', ' ', ' ', ' ', 'W', ' ', ' ', 'R'],
2402
+ [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
2403
+ [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
2404
+ [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
2405
+ [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'U', ' ', ' ', ' ', ' '],
2406
+ [' ', ' ', ' ', ' ', ' ', ' ', ' ', 'L', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
2407
+ [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '],
2408
+ [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'S'],
2409
+ ])
2410
+ top = np.array([2, 2, 4, 2, 1, 2, 1, 2, 4, 1, 3, 2, 5, 2, 2])
2411
+ side = np.array([1, 2, 1, 1, 0, 7, 0, 9, 2, 2, 5, 1, 3, 0, 1])
2412
+ ship_counts = {1: 5, 2: 4, 3: 3, 4: 2, 5: 1}
2413
+ binst = solver.Board(board=board, top=top, side=side, ship_counts=ship_counts)
2414
+ solutions = binst.solve_and_print()
2415
+ ```
2416
+
2417
+
2418
+ **Script Output**
2419
+
2420
+ ```python
2421
+ Solution found
2422
+ [[' ' ' ' ' ' ' ' ' ' 'S' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ']
2423
+ [' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 'S' ' ' 'S' ' ' ' ']
2424
+ [' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 'S' ' ' ' ']
2425
+ [' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 'S' ' ' ' ']
2426
+ [' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ']
2427
+ [' ' 'S' 'S' 'S' 'S' ' ' ' ' ' ' ' ' ' ' ' ' 'S' 'S' 'S' ' ']
2428
+ [' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ']
2429
+ [' ' ' ' 'S' ' ' ' ' 'S' 'S' 'S' 'S' 'S' ' ' ' ' 'S' 'S' 'S']
2430
+ ['S' ' ' 'S' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ']
2431
+ [' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 'S' ' ' ' ' 'S' ' ' ' ' ' ']
2432
+ ['S' 'S' 'S' 'S' ' ' ' ' ' ' ' ' 'S' ' ' ' ' ' ' ' ' ' ' ' ']
2433
+ [' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 'S' ' ' ' ' ' ' ' ']
2434
+ [' ' ' ' ' ' ' ' ' ' ' ' ' ' 'S' 'S' ' ' 'S' ' ' ' ' ' ' ' ']
2435
+ [' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ']
2436
+ [' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 'S']]
2437
+ Solutions found: 1
2438
+ status: OPTIMAL
2439
+ Time taken: 0.12 seconds
2440
+ ```
2441
+
2442
+ **Solved puzzle**
2443
+
2444
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/battleships_solved.png" alt="Battleships solved" width="500">
2445
+
2446
+ ---
2447
+
2448
+ ## Kakurasu (Puzzle Type #30)
2449
+
2450
+ * [**Play online**](https://www.puzzle-kakurasu.com/)
2451
+
2452
+ * [**Solver Code**][30]
2453
+
2454
+ <details>
2455
+ <summary><strong>Rules</strong></summary>
2456
+
2457
+ The goal is to make some of the cells black in such a way that:
2458
+
2459
+ 1. The black cells on each row sum up to the number on the right.
2460
+
2461
+ 2. The black cells on each column sum up to the number on the bottom.
2462
+
2463
+ 3. If a black cell is first on its row/column its value is 1. If it is second its value is 2 etc.
2464
+
2465
+ </details>
2466
+
2467
+ **Unsolved puzzle**
2468
+
2469
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/kakurasu_unsolved.png" alt="Kakurasu unsolved" width="500">
2470
+
2471
+ Code to utilize this package and solve the puzzle:
2472
+
2473
+ ```python
2474
+ from puzzle_solver import kakurasu_solver as solver
2475
+ side = np.array([27, 6, 1, 12, 37, 37, 11, 4, 29, 23, 66, 55])
2476
+ bottom = np.array([22, 1, 25, 36, 10, 22, 25, 35, 32, 28, 45, 45])
2477
+ binst = solver.Board(side=side, bottom=bottom)
2478
+ solutions = binst.solve_and_print()
2479
+ ```
2480
+
2481
+
2482
+ **Script Output**
2483
+
2484
+ ```python
2485
+ Solution found
2486
+ [['X' 'X' ' ' 'X' ' ' ' ' ' ' 'X' ' ' ' ' ' ' 'X']
2487
+ [' ' ' ' ' ' ' ' ' ' 'X' ' ' ' ' ' ' ' ' ' ' ' ']
2488
+ ['X' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ']
2489
+ [' ' ' ' ' ' ' ' 'X' ' ' 'X' ' ' ' ' ' ' ' ' ' ']
2490
+ [' ' ' ' 'X' 'X' ' ' ' ' ' ' 'X' ' ' 'X' ' ' 'X']
2491
+ ['X' ' ' ' ' ' ' 'X' ' ' ' ' 'X' ' ' ' ' 'X' 'X']
2492
+ [' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 'X' ' ']
2493
+ [' ' ' ' ' ' 'X' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ']
2494
+ [' ' ' ' 'X' ' ' ' ' 'X' ' ' ' ' 'X' ' ' 'X' ' ']
2495
+ [' ' ' ' ' ' 'X' ' ' ' ' 'X' ' ' ' ' ' ' ' ' 'X']
2496
+ [' ' ' ' 'X' ' ' ' ' 'X' 'X' 'X' 'X' 'X' 'X' 'X']
2497
+ ['X' ' ' ' ' 'X' ' ' ' ' ' ' 'X' 'X' 'X' 'X' 'X']]
2498
+ Solutions found: 1
2499
+ status: OPTIMAL
2500
+ Time taken: 0.00 seconds
2501
+ ```
2502
+
2503
+ **Solved puzzle**
2504
+
2505
+ <img src="https://raw.githubusercontent.com/Ar-Kareem/puzzle_solver/master/images/kakurasu_solved.png" alt="Kakurasu solved" width="500">
2506
+
2507
+ ---
2508
+
2353
2509
  ---
2354
2510
 
2355
2511
  ## Why SAT / CP-SAT?
@@ -2429,3 +2585,5 @@ Issues and PRs welcome!
2429
2585
  [26]: https://github.com/Ar-Kareem/puzzle_solver/tree/master/src/puzzle_solver/puzzles/thermometers "puzzle_solver/src/puzzle_solver/puzzles/thermometers at master · Ar-Kareem/puzzle_solver · GitHub"
2430
2586
  [27]: https://github.com/Ar-Kareem/puzzle_solver/tree/master/src/puzzle_solver/puzzles/aquarium "puzzle_solver/src/puzzle_solver/puzzles/aquarium at master · Ar-Kareem/puzzle_solver · GitHub"
2431
2587
  [28]: https://github.com/Ar-Kareem/puzzle_solver/tree/master/src/puzzle_solver/puzzles/stitches "puzzle_solver/src/puzzle_solver/puzzles/stitches at master · Ar-Kareem/puzzle_solver · GitHub"
2588
+ [29]: https://github.com/Ar-Kareem/puzzle_solver/tree/master/src/puzzle_solver/puzzles/battleships "puzzle_solver/src/puzzle_solver/puzzles/battleships at master · Ar-Kareem/puzzle_solver · GitHub"
2589
+ [30]: https://github.com/Ar-Kareem/puzzle_solver/tree/master/src/puzzle_solver/puzzles/kakurasu "puzzle_solver/src/puzzle_solver/puzzles/kakurasu at master · Ar-Kareem/puzzle_solver · GitHub"
@@ -1,18 +1,20 @@
1
- puzzle_solver/__init__.py,sha256=J4CxLjjSv2Lbfk5spsG42NR1JcQNrspGpt7Yz3EIx9o,2038
1
+ puzzle_solver/__init__.py,sha256=rqNCaaPZIpdL2Y_Ib96zY8u9Qs_MJaRI3CpJz_vV4_I,2189
2
2
  puzzle_solver/core/utils.py,sha256=3LlBDuie_G0uSlzibpQS2ULmEYSZmpJXh1kawj7rjkg,3396
3
3
  puzzle_solver/core/utils_ortools.py,sha256=qLTIzmITqmgGZvg8XpYAZ4c-lhD5sEDQfS8ECdQ_dkM,3005
4
4
  puzzle_solver/puzzles/aquarium/aquarium.py,sha256=BUfkAS2d9eG3TdMoe1cOGGeNYgKUebRvn-z9nsC9gvE,5708
5
- puzzle_solver/puzzles/bridges/bridges.py,sha256=zUT0TMIu8l982fqDMJfsTnTgqm48nG0iH8flsGT45_E,5489
6
- puzzle_solver/puzzles/chess_range/chess_melee.py,sha256=KnfD_Sxd8bso46eQYpIemp4MIqOUNoonyRVe6soK8kc,231
7
- puzzle_solver/puzzles/chess_range/chess_range.py,sha256=IaldwJR4d0VAUxME2QyvtJdUNzGzDV0FGs1iq9KqsRU,21072
5
+ puzzle_solver/puzzles/battleships/battleships.py,sha256=J1Y-zG2TOmJePCwQnUF8uE9cXL5v8GDVEGv30bQls6k,7467
6
+ puzzle_solver/puzzles/bridges/bridges.py,sha256=15A9uV4xjoqPRo_9CTnoKeGRxS3z2aMF619T1n0dTOQ,5402
7
+ puzzle_solver/puzzles/chess_range/chess_melee.py,sha256=D-_Oi8OyxsVe1j3dIKYwRlxgeb3NWLmDWGcv-oclY0c,195
8
+ puzzle_solver/puzzles/chess_range/chess_range.py,sha256=uMQGTIwzGskHIhI-tPYjT9a3wHUBIkZ18eXjV9IpUE4,21071
8
9
  puzzle_solver/puzzles/chess_range/chess_solo.py,sha256=U3v766UsZHx_dC3gxqU90VbjAXn-OlYhtrnnvJYFvrQ,401
9
10
  puzzle_solver/puzzles/chess_sequence/chess_sequence.py,sha256=6ap3Wouf2PxHV4P56B9ol1QT98Ym6VHaxorQZWl6LnY,13692
10
- puzzle_solver/puzzles/dominosa/dominosa.py,sha256=uh2vsba9HdSHGnYiYE8R_TZzQh5kge51Y1TMRyQlwek,7246
11
+ puzzle_solver/puzzles/dominosa/dominosa.py,sha256=Nmb7pn8U27QJwGy9F3wo8ylqo2_U51OAo3GN2soaNpc,7195
11
12
  puzzle_solver/puzzles/filling/filling.py,sha256=UAkNYjlfxOrYGrRVmuElhWPeW10xD6kiWuB8oELzy3w,9141
12
- puzzle_solver/puzzles/guess/guess.py,sha256=w8ZE-0MswR1_e7_MX622OiCJ8fGTloRHblYFvSA4yHc,10812
13
- puzzle_solver/puzzles/inertia/inertia.py,sha256=xHtQ09sI7hqPcs20foz6YVMuYCsw59TZQxTumAKJuBs,5658
14
- puzzle_solver/puzzles/inertia/tsp.py,sha256=qMyT_W5vBmmaFUB7Cl9rC5xJNdAdQvIJEx6yxlbG9hw,15240
13
+ puzzle_solver/puzzles/guess/guess.py,sha256=sH-NlYhxM3DNbhk4eGde09kgM0KaDvSbLrpHQiwcFGo,10791
14
+ puzzle_solver/puzzles/inertia/inertia.py,sha256=gJBahkh69CrSWNscalKEoP1j4X-Q3XpbIBMiG9PUpU0,5657
15
+ puzzle_solver/puzzles/inertia/tsp.py,sha256=6ZDxdg2f7GDsZeQpnSR2ay0-T4ZhTESJtkKMcm49OS0,15204
15
16
  puzzle_solver/puzzles/inertia/parse_map/parse_map.py,sha256=A9JQTNqamUdzlwqks0XQp3Hge3mzyTIVK6YtDJvqpL4,8422
17
+ puzzle_solver/puzzles/kakurasu/kakurasu.py,sha256=VNGMJnBHDi6WkghLObRLhUvkmrPaGphTTUDMC0TkQvQ,2064
16
18
  puzzle_solver/puzzles/keen/keen.py,sha256=tDb6C5S3Q0JAKPsdw-84WQ6PxRADELZHr_BK8FDH-NA,5039
17
19
  puzzle_solver/puzzles/light_up/light_up.py,sha256=iSA1rjZMFsnI0V0Nxivxox4qZkB7PvUrROSHXcoUXds,4541
18
20
  puzzle_solver/puzzles/magnets/magnets.py,sha256=-Wl49JD_PKeq735zQVMQ3XSQX6gdHiY-7PKw-Sh16jw,6474
@@ -22,19 +24,19 @@ puzzle_solver/puzzles/mosaic/mosaic.py,sha256=QX_nVpVKQg8OfaUcqFk9tKqsDyVqvZc6-X
22
24
  puzzle_solver/puzzles/nonograms/nonograms.py,sha256=1jmDTOCnmivmBlwtMDyyk3TVqH5IjapzLn7zLQ4qubk,6056
23
25
  puzzle_solver/puzzles/pearl/pearl.py,sha256=AP0whWwwZ-1zKingW14OwseYylNAr6NkXSrvdnPU6Rw,8566
24
26
  puzzle_solver/puzzles/range/range.py,sha256=g6ZuHuulYLpNFsqbnPoIB5KoGPllYppU10-Zzqfj5f8,6993
25
- puzzle_solver/puzzles/signpost/signpost.py,sha256=D19ua8rVwO6sgXq4nVLkZfEyz8hqc6qMOk3j-g44soU,3931
27
+ puzzle_solver/puzzles/signpost/signpost.py,sha256=-0_S6ycwzwlUf9-ZhP127Rgo5gMBOHiTM6t08dLLDac,3869
26
28
  puzzle_solver/puzzles/singles/singles.py,sha256=kwMENfqQ-OP3YIz5baY6LRcvYCsNfhImEXN00lwazKM,5658
27
- puzzle_solver/puzzles/stitches/stitches.py,sha256=YvT9WXvUMPLcFGOYXWIPyifCi6caZqRqBTuCgNmcTPQ,6662
28
- puzzle_solver/puzzles/stitches/parse_map/parse_map.py,sha256=_BcYXtDCieKaPOpjG8BFHaFIkbYvMyuwzLL-TmjFZ2k,8786
29
+ puzzle_solver/puzzles/stitches/stitches.py,sha256=iK8t02q43gH3FPbuIDn4dK0sbaOgZOnw8yHNRNvNuIU,6534
30
+ puzzle_solver/puzzles/stitches/parse_map/parse_map.py,sha256=pUB9tG__u4Fq_RCFG_4NNq3LRKAa6FRrvuuL64cUIRM,8866
29
31
  puzzle_solver/puzzles/sudoku/sudoku.py,sha256=M_pry7XyKKzlfCF5rFi02lyOrj5GWZzXnDAxmD3NXvI,3588
30
32
  puzzle_solver/puzzles/tents/tents.py,sha256=iyVK2WXfIT5j_9qqlQg0WmwvixwXlZSsHGK3XA-KpII,6283
31
33
  puzzle_solver/puzzles/thermometers/thermometers.py,sha256=nsvJZkm7G8FALT27bpaB0lv5E_AWawqmvapQI8QcYXw,4015
32
34
  puzzle_solver/puzzles/towers/towers.py,sha256=QvL0Pp-Z2ewCeq9ZkNrh8MShKOh-Y52sFBSudve68wk,6496
33
- puzzle_solver/puzzles/tracks/tracks.py,sha256=VnAtxBkuUTHJYNXr1JGg0yYzJj3kRMBi8Nz7NHKS94A,9089
34
- puzzle_solver/puzzles/undead/undead.py,sha256=ygNugW5SOlYLy6d740gZ2IW9UJQ3SAr9vuMm0ZFr2nY,6630
35
+ puzzle_solver/puzzles/tracks/tracks.py,sha256=0K1YZMHiRIMmFwoD_JxB2c_xB6GYV8spgNUCL-JwDJM,9073
36
+ puzzle_solver/puzzles/undead/undead.py,sha256=IrCUfzQFBem658P5KKqldG7vd2TugTHehcwseCarerM,6604
35
37
  puzzle_solver/puzzles/unruly/unruly.py,sha256=sDF0oKT50G-NshyW2DYrvAgD9q9Ku9ANUyNhGSAu7cQ,3827
36
- puzzle_solver/utils/visualizer.py,sha256=0DP3qs4RC0FDxHNBwPFjk6Y1RDvmLdI1jVFpYweCC00,5878
37
- multi_puzzle_solver-0.9.4.dist-info/METADATA,sha256=4eFPtWAt3CIxMTbbJVZDxU5NCQie7QlXqfAlkNWR3lc,117546
38
- multi_puzzle_solver-0.9.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
39
- multi_puzzle_solver-0.9.4.dist-info/top_level.txt,sha256=exwVUQa-anK9vYrpKzBPvH8bX43iElWI4VeNiAyBGJY,14
40
- multi_puzzle_solver-0.9.4.dist-info/RECORD,,
38
+ puzzle_solver/utils/visualizer.py,sha256=2LmNoxEqb9PGWmBmHW6jh6OqFgNYguavhHB-9Dv5EUw,6113
39
+ multi_puzzle_solver-0.9.6.dist-info/METADATA,sha256=tyAlmP1wgR8sOPLM89MHtUBv_99kGGU7_McS9m9mfRY,124310
40
+ multi_puzzle_solver-0.9.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
41
+ multi_puzzle_solver-0.9.6.dist-info/top_level.txt,sha256=exwVUQa-anK9vYrpKzBPvH8bX43iElWI4VeNiAyBGJY,14
42
+ multi_puzzle_solver-0.9.6.dist-info/RECORD,,
puzzle_solver/__init__.py CHANGED
@@ -1,4 +1,5 @@
1
1
  from puzzle_solver.puzzles.aquarium import aquarium as aquarium_solver
2
+ from puzzle_solver.puzzles.battleships import battleships as battleships_solver
2
3
  from puzzle_solver.puzzles.bridges import bridges as bridges_solver
3
4
  from puzzle_solver.puzzles.chess_range import chess_range as chess_range_solver
4
5
  from puzzle_solver.puzzles.chess_range import chess_solo as chess_solo_solver
@@ -7,6 +8,7 @@ from puzzle_solver.puzzles.dominosa import dominosa as dominosa_solver
7
8
  from puzzle_solver.puzzles.filling import filling as filling_solver
8
9
  from puzzle_solver.puzzles.guess import guess as guess_solver
9
10
  from puzzle_solver.puzzles.inertia import inertia as inertia_solver
11
+ from puzzle_solver.puzzles.kakurasu import kakurasu as kakurasu_solver
10
12
  from puzzle_solver.puzzles.keen import keen as keen_solver
11
13
  from puzzle_solver.puzzles.light_up import light_up as light_up_solver
12
14
  from puzzle_solver.puzzles.magnets import magnets as magnets_solver
@@ -29,4 +31,4 @@ from puzzle_solver.puzzles.unruly import unruly as unruly_solver
29
31
 
30
32
  from puzzle_solver.puzzles.inertia.parse_map.parse_map import main as inertia_image_parser
31
33
 
32
- __version__ = '0.9.4'
34
+ __version__ = '0.9.6'
@@ -0,0 +1,153 @@
1
+ from enum import Enum
2
+ from dataclasses import dataclass, field
3
+ from typing import Optional
4
+ import numpy as np
5
+ from ortools.sat.python import cp_model
6
+
7
+ from puzzle_solver.core.utils import Pos, get_all_pos, get_char, get_neighbors8, set_char, get_row_pos, get_col_pos, get_pos, in_bounds
8
+ from puzzle_solver.core.utils_ortools import generic_solve_all, SingleSolution, or_constraint
9
+
10
+ @dataclass
11
+ class Ship:
12
+ is_active: cp_model.IntVar
13
+ length: int
14
+ top_left_pos: Pos
15
+ body: set[Pos]
16
+ water: set[Pos]
17
+ mid_body: set[Pos] = field(default_factory=set)
18
+ top_tip: Optional[Pos] = field(default=None)
19
+ bottom_tip: Optional[Pos] = field(default=None)
20
+ left_tip: Optional[Pos] = field(default=None)
21
+ right_tip: Optional[Pos] = field(default=None)
22
+
23
+ class Board:
24
+ def __init__(self, board: np.array, top: np.array, side: np.array, ship_counts: dict[int, int]):
25
+ assert board.ndim == 2, f'board must be 2d, got {board.ndim}'
26
+ self.V = board.shape[0]
27
+ self.H = board.shape[1]
28
+ assert top.ndim == 1 and top.shape[0] == self.H, 'top must be a 1d array of length board width'
29
+ assert side.ndim == 1 and side.shape[0] == self.V, 'side must be a 1d array of length board height'
30
+ assert all((str(c.item()) in [' ', 'W', 'O', 'S', 'U', 'D', 'L', 'R'] for c in np.nditer(board))), 'board must contain only spaces, W, O, S, U, D, L, R'
31
+ self.board = board
32
+ self.top = top
33
+ self.side = side
34
+ self.ship_counts = ship_counts
35
+
36
+ self.model = cp_model.CpModel()
37
+ self.model_vars: dict[Pos, cp_model.IntVar] = {}
38
+ self.shipyard: list[Ship] = [] # will contain every possible ship based on ship counts
39
+
40
+ self.create_vars()
41
+ self.init_shipyard()
42
+ self.add_all_constraints()
43
+
44
+ def create_vars(self):
45
+ for pos in get_all_pos(self.V, self.H):
46
+ self.model_vars[pos] = self.model.NewBoolVar(f'{pos}:is_ship')
47
+
48
+ def get_ship(self, pos: Pos, length: int, orientation: str) -> Optional[Ship]:
49
+ assert orientation in ['horizontal', 'vertical'], 'orientation must be horizontal or vertical'
50
+ if length == 1:
51
+ body = {pos}
52
+ top_tip = None
53
+ bottom_tip = None
54
+ left_tip = None
55
+ right_tip = None
56
+ elif orientation == 'horizontal':
57
+ body = set(get_pos(x=x, y=pos.y) for x in range(pos.x, pos.x + length))
58
+ top_tip = None
59
+ bottom_tip = None
60
+ left_tip = pos
61
+ right_tip = get_pos(x=pos.x + length - 1, y=pos.y)
62
+ else:
63
+ body = set(get_pos(x=pos.x, y=y) for y in range(pos.y, pos.y + length))
64
+ left_tip = None
65
+ right_tip = None
66
+ top_tip = pos
67
+ bottom_tip = get_pos(x=pos.x, y=pos.y + length - 1)
68
+ if any(not in_bounds(p, self.V, self.H) for p in body):
69
+ return None
70
+ water = set(p for pos in body for p in get_neighbors8(pos, self.V, self.H))
71
+ water -= body
72
+ mid_body = body - {top_tip, bottom_tip, left_tip, right_tip} if length > 1 else set()
73
+ return Ship(
74
+ is_active=self.model.NewBoolVar(f'{pos}:is_active'),
75
+ length=length,
76
+ top_left_pos=pos,
77
+ body=body,
78
+ water=water,
79
+ mid_body=mid_body,
80
+ top_tip=top_tip,
81
+ bottom_tip=bottom_tip,
82
+ left_tip=left_tip,
83
+ right_tip=right_tip,
84
+ )
85
+
86
+ def init_shipyard(self):
87
+ for length in self.ship_counts.keys():
88
+ for pos in get_all_pos(self.V, self.H):
89
+ for orientation in ['horizontal', 'vertical']:
90
+ if length == 1 and orientation == 'vertical': # prevent double counting 1-length ships
91
+ continue
92
+ ship = self.get_ship(pos, length, orientation)
93
+ if ship is not None:
94
+ self.shipyard.append(ship)
95
+
96
+ def add_all_constraints(self):
97
+ # ship and cells linked
98
+ for ship in self.shipyard:
99
+ for pos in ship.body:
100
+ self.model.Add(self.model_vars[pos] == 1).OnlyEnforceIf(ship.is_active)
101
+ for pos in ship.water:
102
+ self.model.Add(self.model_vars[pos] == 0).OnlyEnforceIf(ship.is_active)
103
+ # constrain the cell to be an OR of all the ships that can be placed at that position
104
+ for pos in get_all_pos(self.V, self.H):
105
+ or_constraint(self.model, self.model_vars[pos], [ship.is_active for ship in self.shipyard if pos in ship.body])
106
+ # force ship counts
107
+ for length, count in self.ship_counts.items():
108
+ self.constrain_ship_counts([ship for ship in self.shipyard if ship.length == length], count)
109
+ # force initial board placement
110
+ for pos in get_all_pos(self.V, self.H):
111
+ c = get_char(self.board, pos)
112
+ if c == 'S': # single-length ship
113
+ self.constrain_ship_counts([ship for ship in self.shipyard if ship.length == 1 and ship.top_left_pos == pos], 1)
114
+ elif c == 'W': # water
115
+ self.model.Add(self.model_vars[pos] == 0)
116
+ elif c == 'O': # mid-body of a ship
117
+ self.constrain_ship_counts([ship for ship in self.shipyard if pos in ship.mid_body], 1)
118
+ elif c == 'U': # top tip of a ship
119
+ self.constrain_ship_counts([ship for ship in self.shipyard if ship.top_tip == pos], 1)
120
+ elif c == 'D': # bottom tip of a ship
121
+ self.constrain_ship_counts([ship for ship in self.shipyard if ship.bottom_tip == pos], 1)
122
+ elif c == 'L': # left tip of a ship
123
+ self.constrain_ship_counts([ship for ship in self.shipyard if ship.left_tip == pos], 1)
124
+ elif c == 'R': # right tip of a ship
125
+ self.constrain_ship_counts([ship for ship in self.shipyard if ship.right_tip == pos], 1)
126
+ elif c == ' ': # empty cell
127
+ pass
128
+ else:
129
+ raise ValueError(f'invalid character: {c}')
130
+ # force the top and side counts
131
+ for row in range(self.V):
132
+ self.model.Add(sum([self.model_vars[p] for p in get_row_pos(row, self.H)]) == self.side[row])
133
+ for col in range(self.H):
134
+ self.model.Add(sum([self.model_vars[p] for p in get_col_pos(col, self.V)]) == self.top[col])
135
+
136
+ def constrain_ship_counts(self, ships: list[Ship], count: int):
137
+ self.model.Add(sum([ship.is_active for ship in ships]) == count)
138
+
139
+ def solve_and_print(self, verbose: bool = True):
140
+ def board_to_solution(board: Board, solver: cp_model.CpSolverSolutionCallback) -> SingleSolution:
141
+ assignment: dict[Pos, int] = {}
142
+ for pos, var in board.model_vars.items():
143
+ assignment[pos] = solver.Value(var)
144
+ return SingleSolution(assignment=assignment)
145
+ def callback(single_res: SingleSolution):
146
+ print("Solution found")
147
+ res = np.full((self.V, self.H), ' ', dtype=str)
148
+ for pos, val in single_res.assignment.items():
149
+ c = 'S' if val == 1 else ' '
150
+ set_char(res, pos, c)
151
+ print(res)
152
+
153
+ return generic_solve_all(self, board_to_solution, callback=callback if verbose else None, verbose=verbose)
@@ -1,12 +1,10 @@
1
- import json
2
1
  from collections import defaultdict
3
- from dataclasses import dataclass
4
2
 
5
3
  import numpy as np
6
4
  from ortools.sat.python import cp_model
7
5
  from ortools.sat.python.cp_model import LinearExpr as lxp
8
6
 
9
- from puzzle_solver.core.utils import Pos, get_all_pos, get_char, set_char, get_neighbors8, get_next_pos, Direction, get_row_pos, get_col_pos
7
+ from puzzle_solver.core.utils import Pos, get_all_pos, get_char, set_char, get_row_pos, get_col_pos
10
8
  from puzzle_solver.core.utils_ortools import generic_solve_all, SingleSolution
11
9
 
12
10
 
@@ -1,5 +1,4 @@
1
1
  from .chess_range import Board as RangeBoard
2
- from .chess_range import PieceType
3
2
 
4
3
  class Board(RangeBoard):
5
4
  def __init__(self, pieces: list[str], colors: list[str]):
@@ -9,7 +9,6 @@ from puzzle_solver.core.utils import Pos, get_pos
9
9
  from puzzle_solver.core.utils_ortools import and_constraint, generic_solve_all, or_constraint
10
10
 
11
11
 
12
-
13
12
  class PieceType(Enum):
14
13
  KING = 1
15
14
  QUEEN = 2
@@ -3,8 +3,8 @@ from collections import defaultdict
3
3
  import numpy as np
4
4
  from ortools.sat.python import cp_model
5
5
 
6
- from puzzle_solver.core.utils import Pos, get_pos, get_all_pos, get_char, set_char, get_row_pos, get_col_pos, Direction, get_next_pos, in_bounds
7
- from puzzle_solver.core.utils_ortools import and_constraint, generic_solve_all, SingleSolution, or_constraint
6
+ from puzzle_solver.core.utils import Pos, get_all_pos, get_char, set_char, Direction, get_next_pos, in_bounds
7
+ from puzzle_solver.core.utils_ortools import generic_solve_all, SingleSolution, or_constraint
8
8
 
9
9
 
10
10
  def get_bool_var(model: cp_model.CpModel, var: cp_model.IntVar, eq_val: int, name: str) -> cp_model.IntVar:
@@ -1,8 +1,9 @@
1
- from collections import defaultdict
2
- import numpy as np
3
- from collections import Counter
1
+ from collections import Counter, defaultdict
4
2
  from itertools import product
5
3
 
4
+ import numpy as np
5
+
6
+
6
7
  class Board:
7
8
  def __init__(self, num_pegs: int = 4, all_colors: list[str] = ['R', 'Y', 'G', 'B', 'O', 'P'], show_warnings: bool = True, show_progress: bool = False):
8
9
  assert num_pegs >= 1, 'num_pegs must be at least 1'
@@ -3,7 +3,6 @@ from collections import defaultdict
3
3
  import numpy as np
4
4
 
5
5
  from puzzle_solver.core.utils import Direction8, Pos, get_all_pos, get_char, in_bounds, get_next_pos
6
-
7
6
  from . import tsp
8
7
 
9
8
 
@@ -1,8 +1,10 @@
1
- from collections import deque, defaultdict
1
+ from collections import defaultdict, deque
2
2
  from typing import Dict, List, Tuple, Set, Any, Optional
3
3
  import random
4
+
4
5
  from ortools.constraint_solver import pywrapcp, routing_enums_pb2
5
6
 
7
+
6
8
  Pos = Any # Hashable node id
7
9
 
8
10
  def solve_optimal_walk(
@@ -81,7 +83,6 @@ def solve_optimal_walk(
81
83
  prev = {n: None for n in nodes}
82
84
  if src not in adj:
83
85
  return dist, prev
84
- from collections import deque
85
86
  q = deque([src])
86
87
  dist[src] = 0
87
88
  while q:
@@ -0,0 +1,46 @@
1
+ import numpy as np
2
+ from ortools.sat.python import cp_model
3
+
4
+ from puzzle_solver.core.utils import Pos, get_all_pos, set_char, get_pos
5
+ from puzzle_solver.core.utils_ortools import generic_solve_all, SingleSolution
6
+
7
+
8
+ class Board:
9
+ def __init__(self, side: np.array, bottom: np.array):
10
+ assert side.ndim == 1, f'side must be 1d, got {side.ndim}'
11
+ self.V = side.shape[0]
12
+ assert bottom.ndim == 1, f'bottom must be 1d, got {bottom.ndim}'
13
+ self.H = bottom.shape[0]
14
+ self.side = side
15
+ self.bottom = bottom
16
+
17
+ self.model = cp_model.CpModel()
18
+ self.model_vars: dict[Pos, cp_model.IntVar] = {}
19
+
20
+ self.create_vars()
21
+ self.add_all_constraints()
22
+
23
+ def create_vars(self):
24
+ for pos in get_all_pos(self.V, self.H):
25
+ self.model_vars[pos] = self.model.NewBoolVar(f'{pos}')
26
+
27
+ def add_all_constraints(self):
28
+ for row in range(self.V):
29
+ self.model.Add(sum([self.model_vars[get_pos(x=col, y=row)] * (col + 1) for col in range(self.H)]) == self.side[row])
30
+ for col in range(self.H):
31
+ self.model.Add(sum([self.model_vars[get_pos(x=col, y=row)] * (row + 1) for row in range(self.V)]) == self.bottom[col])
32
+
33
+ def solve_and_print(self, verbose: bool = True):
34
+ def board_to_solution(board: Board, solver: cp_model.CpSolverSolutionCallback) -> SingleSolution:
35
+ assignment: dict[Pos, int] = {}
36
+ for pos, var in board.model_vars.items():
37
+ assignment[pos] = solver.value(var)
38
+ return SingleSolution(assignment=assignment)
39
+ def callback(single_res: SingleSolution):
40
+ print("Solution found")
41
+ res = np.full((self.V, self.H), ' ', dtype=object)
42
+ for pos in get_all_pos(self.V, self.H):
43
+ c = 'X' if single_res.assignment[pos] else ' '
44
+ set_char(res, pos, c)
45
+ print(res)
46
+ return generic_solve_all(self, board_to_solution, callback=callback if verbose else None, verbose=verbose)
@@ -1,10 +1,8 @@
1
- from enum import Enum
2
-
3
1
  import numpy as np
4
2
  from ortools.sat.python import cp_model
5
3
  from ortools.sat.python.cp_model import LinearExpr as lxp
6
4
 
7
- from puzzle_solver.core.utils import Pos, get_all_pos, get_char, set_char, in_bounds, get_next_pos, Direction, get_row_pos, get_col_pos, Direction8
5
+ from puzzle_solver.core.utils import Pos, get_all_pos, get_char, set_char, in_bounds, get_next_pos, Direction8
8
6
  from puzzle_solver.core.utils_ortools import generic_solve_all, SingleSolution
9
7
 
10
8
 
@@ -206,4 +206,5 @@ def main(image):
206
206
  if __name__ == '__main__':
207
207
  # to run this script and visualize the output, in the root run:
208
208
  # python .\src\puzzle_solver\puzzles\stitches\parse_map\parse_map.py | python .\src\puzzle_solver\utils\visualizer.py --read_stdin
209
- main(Path(__file__).parent / 'input_output' / 'MTM6OSw4MjEsNDAx.png')
209
+ # main(Path(__file__).parent / 'input_output' / 'MTM6OSw4MjEsNDAx.png')
210
+ main(Path(__file__).parent / 'input_output' / 'weekly_oct_3rd_2025.png')
@@ -1,11 +1,9 @@
1
- from collections import defaultdict
2
1
  from typing import Union
3
2
 
4
3
  import numpy as np
5
4
  from ortools.sat.python import cp_model
6
- from ortools.sat.python.cp_model import LinearExpr as lxp
7
5
 
8
- from puzzle_solver.core.utils import Pos, get_all_pos, get_char, get_neighbors4, set_char, get_neighbors8, get_next_pos, Direction, get_row_pos, get_col_pos, in_bounds, get_opposite_direction
6
+ from puzzle_solver.core.utils import Pos, get_all_pos, get_char, set_char, get_next_pos, Direction, get_row_pos, get_col_pos, in_bounds, get_opposite_direction
9
7
  from puzzle_solver.core.utils_ortools import generic_solve_all, SingleSolution, and_constraint
10
8
 
11
9
 
@@ -2,7 +2,7 @@ from collections import defaultdict
2
2
  import numpy as np
3
3
  from ortools.sat.python import cp_model
4
4
 
5
- from puzzle_solver.core.utils import Pos, get_all_pos, set_char, get_char, get_neighbors4, Direction, in_bounds, get_next_pos, get_row_pos, get_col_pos, get_opposite_direction
5
+ from puzzle_solver.core.utils import Pos, get_all_pos, set_char, get_char, Direction, in_bounds, get_next_pos, get_row_pos, get_col_pos, get_opposite_direction
6
6
  from puzzle_solver.core.utils_ortools import generic_solve_all, SingleSolution, and_constraint, or_constraint
7
7
 
8
8
 
@@ -6,7 +6,7 @@ import numpy as np
6
6
  from ortools.sat.python import cp_model
7
7
  from ortools.sat.python.cp_model import LinearExpr as lxp
8
8
 
9
- from puzzle_solver.core.utils import Pos, get_all_pos, set_char, get_pos, get_next_pos, in_bounds, get_char, Direction, get_row_pos, get_col_pos
9
+ from puzzle_solver.core.utils import Pos, get_all_pos, set_char, get_pos, get_next_pos, in_bounds, get_char, Direction
10
10
  from puzzle_solver.core.utils_ortools import generic_solve_all, SingleSolution
11
11
 
12
12
 
@@ -123,6 +123,13 @@ def get_input():
123
123
 
124
124
  if __name__ == '__main__':
125
125
  board = get_input()
126
+ print('Visualizing board:')
127
+ print('[')
128
+ for i,row in enumerate(board):
129
+ print(' [' + ', '.join([f"'{c}'" for c in row]) + ']', end='')
130
+ if i != len(board) - 1:
131
+ print(',')
132
+ print('\n]')
126
133
  # rcolors = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0), (0, 255, 255), (255, 0, 255), (255, 255, 255), (128, 128, 128)]
127
134
  vs =[0, 128, 255]
128
135
  rcolors = [(v1, v2, v3) for v1 in vs for v2 in vs for v3 in vs if (v1, v2, v3) != (0, 0, 0)]