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
Metadata
Release files for akari-sat 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| akari_sat-0.1.2.tar.gz | 9.5 kB | Without provenance | Details for akari_sat-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| akari_sat-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for akari_sat-0.1.2-py3-none-any.whl |
Total release size: 14.5 kB
Release files / akari_sat-0.1.2.tar.gz
| Download URL | akari_sat-0.1.2.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bf079d24574a066dbf80297cdb9ee6136acc304e85c0efc0cce2fd720674794e
|
|
BLAKE2b-256 checksum How to use checksums |
ca0348618ef0c814c672e2ebd72c41ec5d46bc7b2d4def53dcaa41ee726d75b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.12
|
Release files / akari_sat-0.1.2-py3-none-any.whl
| Download URL | akari_sat-0.1.2-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9d33779898d8e1b282dc26a3a1a5bfe25339bedfd58807fdfb0a3e5a6666386d
|
|
BLAKE2b-256 checksum How to use checksums |
a11c06fb217fcc03786910927fe0723fc73e6c413a10b3b8869b85f626e0a11b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.12
|
Security for akari-sat 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.