A. 1 ......... They all contain syntax errors!

The cat drinks the milk Missing period.
The drinks milk cat the. drinks is not a noun.
The cat drinks milk. Milk is not an article.


















































A. 2 ......... When the program fragment is executed, it causes Shakey to step backwards one square. We could comment the program like this:

// Take one step backwards.

// 1. First turn around.
left();
left();

// 2. Now take the step.
step();

// 3. Finally, turn around again, so Shakey is
//    facing in the original direction.
left();
left();

If we remove all the code from the above example, then we are just left with the comments, which gives us a variant of the program solution:

// Take one step backwards.
// 1. First turn around.
// 2. Now take the step.
// 3. Finally, turn around again, so Shakey is
//    facing in the original direction.

Your initial design of a program solution in pseudocode will typically end up corresponding to comments in the actual code.


















































A. 3 ......... No! If Shakey executes an instruction that results in an error, then this instruction is not included in the program under construction. In the case of a bad step, only a comment appears in the program.

















































A. 4 ......... You get a run-time, or semantic, error! Only one item may appear in a single grid location. There is already an item at the precise point where Shakey tries to execute the drop instruction.

Notice that the program does not run to completion. It stops early, as soon as the error is detected.


















































A. 5 ......... Yes!

















































A. 6 ......... Error! Those hurdles are walls!

















































A. 7 ......... Here's one possible solution. It is commented differently than the automatically generated comments that you see in the text window, but these comments should clarify the logical structure of the program.

function main() {
  // Hurdles world loaded.
  home();

  //-----------------------
  // JUMP THE FIRST HURDLE.
  //-----------------------
  // Take off...
  right();
  step();
  left();

  // Go up the left side...
  step();
  step();
  step();

  // Round the top and pickup the flag...
  right();
  step();
  pickup();
  step();
  right();

  // Go down the right side...
  step();
  step();
  step();

  // Get set for the next jump...
  left();
  step();
  left();

  //------------------------
  // JUMP THE SECOND HURDLE.
  //------------------------
  // Take off...
  right();
  step();
  left();

  // Go up the left side...
  step();
  step();
  step();

  // Round the top and pickup the flag...
  right();
  step();
  pickup();
  step();
  right();

  // Go down the right side...
  step();
  step();
  step();

  // Get set for the next jump...
  left();
  step();
  left();

  //-----------------------
  // JUMP THE THIRD HURDLE.
  //-----------------------
  // Take off...
  right();
  step();
  left();

  // Go up the left side...
  step();
  step();
  step();

  // Round the top and pickup the flag...
  right();
  step();
  pickup();
  step();
  right();

  // Go down the right side...
  step();
  step();
  step();

  // Get set for the next jump...
  left();
  step();
  left();

  //----------------------------------
  // JUMP THE FORTH (AND LAST) HURDLE.
  //----------------------------------
  // Take off...
  right();
  step();
  left();

  // Go up the left side...
  step();
  step();
  step();

  // Round the top and pickup the flag...
  right();
  step();
  pickup();
  step();
  right();

  // Go down the right side...
  step();
  step();
  step();

  // Get set for the next jump...
  left();
  step();
  left();
}

One thing to notice is that the code fragment for jumping the first hurdle is exactly the same as the code fragment for jumping the second (and third, and forth) hurdle.

If we remove all the distracting commands, then we are left with only the comments, which gives us a nice pseudo-code version of the program.

  // Hurdles world loaded.

  //-----------------------
  // JUMP THE FIRST HURDLE.
  //-----------------------
  // Take off...
  // Go up the left side...
  // Round the top and pickup the flag...
  // Go down the right side...
  // Get set for the next jump...

  //------------------------
  // JUMP THE SECOND HURDLE.
  //------------------------
  // Take off...
  // Go up the left side...
  // Round the top and pickup the flag...
  // Go down the right side...
  // Get set for the next jump...

  //-----------------------
  // JUMP THE THIRD HURDLE.
  //-----------------------
  // Take off...
  // Go up the left side...
  // Round the top and pickup the flag...
  // Go down the right side...
  // Get set for the next jump...

  //----------------------------------
  // JUMP THE FORTH (AND LAST) HURDLE.
  //----------------------------------
  // Take off...
  // Go up the left side...
  // Round the top and pickup the flag...
  // Go down the right side...
  // Get set for the next jump...
}

One advantage of this particular solution is that it generalizes nicely. It's fairly easy to see how to extend this program to make Shakey jump five or six hurdles.