Warning
This page is located in archive.

02 Solvability

programming task - solvability n-1 puzzle

Is the given configuration/state solvable at all? The actual algorithm will be explained at the second lecture. The essential pieces of implementation will be shown live during the computer lab. You can use also the code from npuzzle.py and compare it to your solution of npuzzle.py.

The task is to implement a method is_solvable(env), which decides whether a given env (NPuzzle instance) is solvable or not. Implement the function in a module named solvability_check.py and upload it to BRUTE. A correct solution is worth 2 points.

Example structure of (solvability_check.py):

import npuzzle
 
def is_solvable(env):
    '''
    True or False?
    '''
    # your code comes here
 
if __name__=="__main__": # testing suite
    env = npuzzle.NPuzzle(3) # instance of NPuzzle class
    env.reset()              # random shuffle
    env.visualise()          # just to show the board
    # just check
    print(is_solvable(env))  # should output True or False

When done, upload to the BRUTE

Extra

A link to the N-Puzzle solver.

courses/be5b33kui/labs/weekly/week_02.txt · Last modified: 2018/02/26 15:33 by svarnpet