Step 13: The Program
The more detailed function is that of shortening the path. A letter is stored at every intersection that indicates the direction the robot took. If the previous letter was a "B", indicating a wrong turn, the function that shortens the path is run to substitute letters in place of those 3 letter sequences outlined earlier.
Finally there is a function that replays the shortest path that the robot calculated when the robot is picked up and then placed back down on the black line. The robot can detect when it is placed back down and then runs the shortest calculated path.
You can view the code here or of course download it on this page.