Skip to main content

Add your description here

Project description

Akari Solver

アカリ(美術館 / Light Up)パズルを SAT ソルバーで解くソルバーです。盤面の制約を CNF に変換し、PySAT(Glucose3)で求解します。

必要環境

  • Python 3.13 以上
  • PySAT
uv add akari-sat

ディレクトリ構成

project/
├── main.py
└── src/
    ├── __init__.py
    └── akari_solver.py

使い方

プロジェクトルートで実行します。

uv run main.py
from src.akari_solver import solve_akari

grid = [
    "..#..",
    "2....",
    "..1..",
    "....0",
    "..#..",
]
H, W = len(grid), len(grid[0])

result = solve_akari(H, W, grid)   # 解けない場合は None
if result is not None:
    for r in range(H):
        print("".join("*" if result[r][c] else grid[r][c] for c in range(W)))

入力・出力

入力: grid … 1 行 1 文字列のリスト(list[str])、または 1 文字ずつの 2 次元配列(list[list[str]])。各マスの文字は以下の通り。

文字 意味
. 空きマス
# 数字のない壁
04 数字付きの壁

出力: … H×W の真偽値の 2 次元配列 list[list[bool]]result[r][c] が r 行 c 列に灯があるかを表す。解が存在しない場合は None

ルール(エンコード内容)

アカリの 4 つの規則を制約として SAT に与えています。

  • 壁・数字マスには灯を置かない
  • 数字マスの上下左右に接する灯の数は、その数字とちょうど一致する
  • 同じ行・列で壁を挟まずに 2 つ以上の灯を置かない(灯どうしは照らし合わない)
  • すべての空きマスがいずれかの灯に照らされる

Project details


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.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

akari_sat-0.1.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file akari_sat-0.1.0.tar.gz.

File metadata

  • Download URL: akari_sat-0.1.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.12

File hashes

Hashes for akari_sat-0.1.0.tar.gz
Algorithm Hash digest
SHA256 65608f028f6c773a9d73b014eb6683400d9304b03276f77a0ad61639b0adb333
MD5 da51558f970b233a2360149067188f75
BLAKE2b-256 081ed08afc710c552494280447a8d7cc56c29e4065fe7c11804406d62bde4505

See more details on using hashes here.

File details

Details for the file akari_sat-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: akari_sat-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.12

File hashes

Hashes for akari_sat-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 55c95caeafa410312921a6598510a56a4e49ff711e11c331fed0420ebe2fe41b
MD5 9c0b5857750f2b79c45826378dd0562e
BLAKE2b-256 8547af191099c9abc701bce1a34b4866cfb21c223f52793bf9fc9f7c2f9d676b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page