# Lab 3: More on Oolong

Remember, if you haven't already done this permanently, you'll need to set your path correctly:

```
set path = ( \$path /package/jpower/se209/bin )
```

### Iteration

To get a little practice with iteration (labels and jumps in oolong), try implementing methods that implement the following functions:
1. Triangular numbers:
• tri(1)=1,
• tri(i)=i+tri(i-1), for i>1
2. The Fibonacci sequence:
• fib(0) = fib(1) = 1,
• fib(i)=fib(i-1)+fib(i-2), for i>1
3. Square root of some number N by guessing:
• guess(0)=N,
• guess(i) = (guess(i-1) + N/guess(i-1))/2, for i>0
Here is a sample solution.

### Robots

Here's the source code for a simple robot that I was using with the first years. Your task is to write a controller for the robot - the program should run by taking a list of instructions in using the command line arguments.

Each robot knows its location - in (across,down) co-ordinates - and its orientation - north, south, east or west. You can issue commands to the robot to move it around. The valid commands are:

 L Turn 90 degrees to the left R Turn 90 degrees to the right F num Move forward by num steps (in the current direction) D Calculate the distance from the origin, rounded down to a whole number

For example, here is a sequence of commands to move the robot five steps forward, four to the left, and six steps backwards again: (The robot is initially facing north)

```F 5 L F 4 L F 6 D
```
Your program should create a Robot object and then go through the comand line arguments, calling the appropriate method to perform each action.

 James Power, Dept. of Computer Science Last revised: 6 March 2000