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
return sum
How can I make this faster?
Edit:
misplacedTilesHeuristic((4, 5, 3, 1, 0, 6, 7, 2, 8), (0, 1, 2, 3, 4, 5, 6, 7, 8))
as already mentioned, the one-liner is a good idea, for example like this :
Benchmark:
The prop1() shows the best times for the moment with almost 34.4% better performance, but I think that it could be better :)