sliding-tile-puzzle

How can I speed up my misplaced tiles heuristic for the 8 puzzle problem?

How can I speed up my misplaced tiles heuristic for the 8 puzzle problem? Question: My lists are always of length 8 (7 indices), and always contain numbers 0-8 I currently do this to find the sum of misplaced tiles: def misplacedTilesHeuristic(stateObj, goal): sum = 0 for elem in range(len(goal)): if goal[elem] != stateObj[elem]: sum+=1 …

Total answers: 2