Puzzle solver

Solver for the rectangular 2D version of this.