mouse
cheese

CheeseMaze

This is a demonstration of finding the optimal path through a maze. The mouse has no prior knowledge of the layout of the maze except for the location of the cheese. I tried various recursive algorithms which turned out to be woefully inefficient, before hitting on this deceptively simple one: start from a map which is empty except for the walls the mouse has already seen, perform a breadth-first search of the exits of each square starting from the cheese, and when you reach a square adjacent to the mouse, that square is the mouse's next move.

Implemented in 4 lines of Javascript (sort of...) for the Ozone Asylum 20lines Javascript Contest, October 2004 ("A.I.")