Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
16-liner: no import solution in Clear category for Stepping Stones Puzzle by przemyslaw.daniel
def stepping_stones(size: int, ones: list[tuple[int, int]]) -> int:
""" Solving stepping stones puzzle """
neighbors = -1, -1 + 1j, 1j, 1 + 1j, 1, 1 - 1j, -1j, -1 - 1j
valid = {x + 1j*y for x in range(size) for y in range(size)}
stack, best = [(1, {x + 1j*y: 1 for x, y in ones})], 0
while stack:
level, board = stack.pop()
best = max(best, level)
candidates = {pos + neigh for pos in board for neigh in neighbors}
for current in candidates & valid - set(board):
value = sum(board.get(current + neigh, 0) for neigh in neighbors)
if value == level + 1:
stack += [(value, board | {current: value})]
return best
Jan. 26, 2023