Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions 8 search.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ def astar_search(problem, h=None):
class EightPuzzle(Problem):

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

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

inversion = 0
for i in range(len(state)):
for j in range(i, len(state)):
if state[i] > state[j] != 0:
for j in range(i+1, len(state)):
if (state[i] > state[j]) and state[i] != 0 and state[j]!= 0:
inversion += 1

return inversion % 2 == 0
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.