Solving a 7x7 maze puzzle
You're finding all solutions, but because the code overwrites the &lt;span&gt; for every solution found you only see the last one. Try this:

sp.innerHTML += 'solved in ' + h.length + ' steps&lt;br/&gt;';


You're performing a breadth-first search of all possible paths through the maze which is what I ended up going with. By scheduling timer events you're essentially queueing up cells. I did the same but with an actual queue of cells to visit.

This is the core of my Scala version.

// pathTo tracks the best path to each point
// moves(Point) returns the number in that cell

val queue = new Queue[Point]
queue enqueue new Point(0, 0)  // start from top-left
while (!queue.isEmpty) {
    val start = queue dequeue
    val path = pathTo(start)
    (UP, DOWN, LEFT, RIGHT) foreach { direction =&gt;
        val end = start.move(direction, moves(start))
        if (end != None &amp;&amp; !pathTo.contains(end)) {
            pathTo(end) = path + end
            queue enqueue end
        }
    }
}