19 January 2007

8 line solution to Labyrinth maze program

Here is the solution: 
1 EXIT? 8 2 
2 WALL? 3 5 
3 RIGHT 
4 GOTO 1 
5 STEP 
6 LEFT 
7 GOTO 1 
8 QUIT 

 An explanation: The basic idea is that if you always turn in the same direction and follow the walls, you will eventually find the exit. There is an annual maze competition using robotic mice and one year a team worked this out and built a faster mouse instead of a smarter mouse and they won! The program first checks to see if the robot is at the exit. If it is the program ends, if not it looks in front to see if there is a wall. If there is a wall then turn right and start the cycle again. If there isn't a wall, take a step forward, turn left and start the cycle again.