akari-sat
アカリ(美術館 / Light Up)パズルを SAT ソルバーで解く Python ライブラリです。 盤面のルールを CNF 制約に変換し、PySAT(Glucose3)で求解します。
インストール
pip install akari-sat
uv を使う場合:
uv add akari-sat
使い方
インストール後、akari_sat パッケージから solve_akari を読み込んで使います。
from akari_sat import solve_akari
grid = [
"..#..",
"2....",
"..1..",
"....0",
"..#..",
]
H, W = len(grid), len(grid[0])
result = solve_akari(H, W, grid) # 解が存在しない場合は None
if result is None:
print("解が見つかりませんでした(充足不能)")
else:
for r in range(H):
print("".join("*" if result[r][c] else grid[r][c] for c in range(W)))
実行結果(* が灯り):
*.#.*
2.*..
*.1..
.*..0
..#*.
API
solve_akari(H, W, grid, solver=Glucose3)
アカリを解きます。
引数:
H(int): グリッドの高さ。W(int): グリッドの幅。grid(list[str] | list[list[str]]): 盤面。1 行 1 文字列のリスト、または 1 文字ずつの 2 次元配列で渡します。solver: 使用する PySAT のソルバークラス。デフォルトはGlucose3。
戻り値:
list[list[bool]]:H×Wの真偽値の 2 次元配列。result[r][c]が r 行 c 列に灯があるかを表します。- 解が存在しない場合は
None。
各マスの文字の意味:
| 文字 | 意味 |
|---|---|
. |
空きマス |
# |
数字のない壁 |
0–4 |
数字付きの壁 |
エンコードしているルール
アカリの 4 つの規則を制約として SAT に与えています。
- 壁・数字マスには灯を置かない。
- 数字マスの上下左右に接する灯の数は、その数字とちょうど一致する。
- 同じ行・列で壁を挟まずに 2 つ以上の灯を置かない(灯どうしは照らし合わない)。
- すべての空きマスがいずれかの灯に照らされる。
動作環境
- Python 3.13 以上
- python-sat(依存パッケージとして自動的に導入されます)
リポジトリ
https://github.com/youseiushida/akari-sat
ライセンス
MIT License
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
akari_sat-0.1.2.tar.gz
(9.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file akari_sat-0.1.2.tar.gz.
File metadata
- Download URL: akari_sat-0.1.2.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf079d24574a066dbf80297cdb9ee6136acc304e85c0efc0cce2fd720674794e
|
|
| MD5 |
c04bd05b22560b719bb2f9da44d69975
|
|
| BLAKE2b-256 |
ca0348618ef0c814c672e2ebd72c41ec5d46bc7b2d4def53dcaa41ee726d75b7
|
File details
Details for the file akari_sat-0.1.2-py3-none-any.whl.
File metadata
- Download URL: akari_sat-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d33779898d8e1b282dc26a3a1a5bfe25339bedfd58807fdfb0a3e5a6666386d
|
|
| MD5 |
62c2bb52c15acaa410bfd96451d49670
|
|
| BLAKE2b-256 |
a11c06fb217fcc03786910927fe0723fc73e6c413a10b3b8869b85f626e0a11b
|