Puzzle Solving Algorithm