Iterative form of puzzle-solver