B CUSP 110C – Digital Thinking Homework 2: Programming with Lightbot

Goal: The purpose of this assignment is to look at textual ways of programming the bot, or commanding the bot symbolically.

When we solved the Lightbot 2.0 exercises last time, we programmed the bot using a tiny list of instructions presented iconigraphically, that is, as pictures. But, these could just as easily be written symbolically, that is, as text. So, our instruction list

can be expressed symbolically,

Step  Right Left  Jump Power   AnyName

as shown. When we program symbolically, we don’t have to call the functions F1 and F2. We can give them actual names like turn_around for a function that causes the bot to turn around. So, we can give the symbolic solution to

as

Left, Step, Right, Step, Step, Step, Step, Right, Step, Power.

or more succinctly, LSRSSSSRSP. Symbolic expression is the same thing, just a different form with slightly different properties as we now see.

## Iteration

We notice that often in programming the bot we need to repeat operations, such as the four steps in the example. (We previously used recursion to repeat instructions, but there is another way.) Wouldn’t it be easier if instead of all of the dragging or typing, we just wrote 4Step or Step4 or some other similar form? Yes, of course. So, we will use the form 4:Step to mean to do the Step operation 4 times; more generally we write <number>:<operation>, where the operation is one of our basic instructions given above like Step, or perhaps a list of them grouped inside of a parenthesis pair, as in 3:(Jump, Power, Step, Step), which will do the four-instruction sequence 3 times.

Assignment. Give symbolic programs for the Lightbot’s problems 2a, 2b and 2c, writing them with WORD. If iteration can be profitably used, use it. Caution: Check your work to be sure you’ve got it right.

(2a)                                                                  (2b)

(2c)

## Wrap Up

In this assignment you learned about iteration and the symbolic representation of instructions. You will use both extensively in the future.

## Submit

Deposit your WORD file (with your name as part of the file name) in the course assignment drop box; see course web page. In addition, please bring a hard copy to class to submit on Tuesday. Don’t forget to put your name on the print out. Once again, you are to submit both soft and hard copies!