Labyrinth Solver

What about a labyrinth solver function in 16 lines of Python? :-)

This entry was posted in Python, Snippet. Bookmark the permalink.

4 Responses to Labyrinth Solver

  1. Eduardo Habkost says:

    When I first read the text, I thought “What? A solution to Labyrinthitis?”

  2. A cure to labyrinthitis in 16 lines of Python would be *really* nice. Hehehe :-)

  3. Dinu says:

    Even shorter, but also more cryptic ;-)

    from operator import or_
        if reduce(or_, [solve(maze, posx+i, posy+j, sizex, sizey)
                        for i,j in zip((1,-1,0,0), (0,0,1,-1))]):
    

    instead of:

        if (solve(maze, posx+1, posy, sizex, sizey) or
            solve(maze, posx-1, posy, sizex, sizey) or
            solve(maze, posx, posy+1, sizex, sizey) or
            solve(maze, posx, posy-1, sizex, sizey)):
    
  4. Spence says:

    How could this program print an output of the maze for every position the program moves?

Leave a Reply

Your email address will not be published. Required fields are marked *