Skip to content

Commit 4eebaca

Browse files
SandersLinnorvig
authored andcommitted
Fixed small errors (#987)
1 parent df236b8 commit 4eebaca

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

search.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ def astar_search(problem, h=None):
415415
class EightPuzzle(Problem):
416416

417417
""" The problem of sliding tiles numbered from 1 to 8 on a 3x3 board,
418-
where one of the squares is a blank. A state is represented as a 3x3 list,
419-
where element at index i,j represents the tile number (0 if it's an empty square) """
418+
where one of the squares is a blank. A state is represented as a tuple of length 9,
419+
where element at index i represents the tile number at index i (0 if it's an empty square) """
420420

421421
def __init__(self, initial, goal=(1, 2, 3, 4, 5, 6, 7, 8, 0)):
422422
""" Define goal state and initialize a problem """
@@ -472,8 +472,8 @@ def check_solvability(self, state):
472472

473473
inversion = 0
474474
for i in range(len(state)):
475-
for j in range(i, len(state)):
476-
if state[i] > state[j] != 0:
475+
for j in range(i+1, len(state)):
476+
if (state[i] > state[j]) and state[i] != 0 and state[j]!= 0:
477477
inversion += 1
478478

479479
return inversion % 2 == 0

0 commit comments

Comments
 (0)