Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
11-liner: simple solution in Clear category for 15-puzzle Solvability by przemyslaw.daniel
from itertools import combinations
def fifteen_puzzle(tiles: list[list[int]], blank: int = 16) -> bool:
tiles = sum(tiles, [])
row = tiles.index(blank) // 4 + 1
tiles.remove(blank)
inversions = sum(x > y for x, y in combinations(tiles, r=2))
return not (inversions + row) % 2
March 26, 2023
Comments: