by Gustavo Niemeyer
What about a labyrinth solver function in 16 lines of Python?
When I first read the text, I thought “What? A solution to Labyrinthitis?”
A cure to labyrinthitis in 16 lines of Python would be *really* nice. Hehehe
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)):
Name (required)
Mail (will not be published) (required)
Website
When I first read the text, I thought “What? A solution to Labyrinthitis?”
A cure to labyrinthitis in 16 lines of Python would be *really* nice. Hehehe
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)):