I changed the way the algorithm works, so that it more systematically checks all possible paths for all possible mazes and is guaranteed to eventually find the shortest possible set of instructions that will solve every maze of size n x n. The bad news is that it takes a long time to run. Even after doing what I could to make this run reasonably efficiently, it still could only process a 3 x 3 maze and will take a while to process even a 4 x 4 maze, albeit on a crummy laptop.
If this was a question posed to programmers, and the person asking the question knew full well that the numbers would get huge fast (checking all possible instructions for a 17 step solution would mean checking 417 = 17 billion potential solutions against almost 4000 mazes for the 4 x 4 case) and was making the point that you'll need to come up with something other than exhaustive brute force (sort of like the algorithm I had earlier but probably a smarter version), then it would make sense.
At any rate, this is a solution for any 3 x 3 maze with the shortest possible number of moves.