MCPcopy Create free account
hub / github.com/geekcomputers/Python / print_solution

Function print_solution

8_puzzle.py:87–99  ·  view source on GitHub ↗

Print step-by-step solution from initial to goal state.

(solution: Optional[PuzzleState])

Source from the content-addressed store, hash-verified

85
86
87def print_solution(solution: Optional[PuzzleState]) -> None:
88 """Print step-by-step solution from initial to goal state."""
89 if not solution:
90 print("No solution found.")
91 return
92 steps = []
93 while solution:
94 steps.append(solution.board)
95 solution = solution.previous
96 for step in reversed(steps):
97 for row in step:
98 print(" ".join(map(str, row)))
99 print()
100
101
102if __name__ == "__main__":

Callers

nothing calls this directly

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected