Greetings, new employee of Amazoo! As a reminder, all company facilities are monitored by helpful surveillance and same-day delivery drones.
You will be learning to write programs that control this wonderful device in order to deliver bales of hay to the many barns of our great leader, Director Jeff Hayzos.
The program below is a sequence containing three instructions, the boxes with arrows pointing towards the east (the right side of the screen). Press “Run Code” to watch the Amazoo drone go east until it goes out of bounds (into a dark square) and crashes.
Once the drone crashes, press the "Try Again" button. This will restore the drone to its original position.
After clicking Try Again, the program can be modified. Click and drag the first instruction away so only two instructions remain. This will result in the Eye of Amazoo stopping at the pink barn.
A program is made up of instructions that can be understood both by humans and computers. Humans need to understand the instructions in order to read, write, and share programs. Computers need to understand the instructions in order to bring the programs to life by running them.
The available instructions for the drone are above the program, and you can drag them down onto the program.
In this example, you only have two of the four directional instructions available, though you can use each instruction as many times as you want.
You have been given a program that will guide the drone to the pink Barn #6. Which of the other barns are reachable?
The sequence of instructions that you give your drone is a stored program. After you write the program down once, the drone can execute those instructions again and again. Being able to repeat a set of instructions again and again is part of what makes automation powerful!
The very first stored program ever executed was written for an experimental computer called the Manchester Baby. The program was seventeen instructions long, which was important because the computer could only store thirty-two instructions!
Modern computers seem like they can hold an endless number of instructions compared to primitive computers like the Manchester Baby. Nevertheless, computer scientists will always find themselves running into limitations, because computer science is, in part, about interacting with a complex world using limited options and finite storage.
Your drone is even more ridiculously limited than the Manchester Baby: it can only hold five instructions! But Director Hayzos demands that all possible hay deliveries should still be made.
The instructions given guide the drone to the pink Barn #6. Change them to fly to the red Barn #1 instead.
So far, your programs have been very, very simple: the drone has just executed a sequence of instructions, one simple instruction at a time. Computer programs get more interesting when you can repeat instructions multiple times.
Press "Run Code" to see the repetition instruction in action. The instruction contains a counter and takes the alternate path until its counter hits zero.
The program above uses the repetition instruction once and basic directional instructions four times (three East instructions and one South instruction). Without this new repetition instruction, how many basic directional instructions would your drone need to get to the pink Barn #6?
Repetition instructions allow you to make better use of limited space, but they also make programs a great deal more complex!
These instructions again guide the drone to the pink Barn #6. You can add a repetition instruction by dragging it on the program and then clicking at the position where you want the alternate path to go.
The instructions below are a program that delivers hay to the pink Barn #6.
You can also call this program an algorithm: it's a specific procedure you can follow to achieve a goal in a systematic fashion.
Sometimes, when computer scientists talk about algorithms, they are referring to a precise description of an automatic process that is tuned for human communication and not understandable by a computer. An algorithm does not necessarily need to be something that can be immediately executed by a computer.
Here's a description of what the program above does: “Have the drone go north and then east, and then repeat that three more times. Finally, go east and then south once.” Those two sentences are certainly not a program, but they are an extremely simple algorithm.
When a precise English description of a process and a program communicate the same process, you can say that the specific program is implementing the algorithm.
Which algorithm does this program implement?
In this exploration, your programs solved very specific problems, navigating the drone through a specific grid. Many algorithms solve more general tasks and can make decisions that the programmer didn't completely describe ahead of time.
One example is route-finding on a map. Given the drone's position, its desired destination, and a map, it's possible for an algorithm to actually find the correct instructions for getting to the destination. That's an algorithm writing an algorithm!
Another example is navigating in an uncertain environment. If your delivery drone doesn't have a perfect map of all obstacles ahead of time, then you can write a program that takes inputs from its sensors and turns them into movements that try to guide the drone towards the goal.
Congratulations, new employee! You have shown yourself competent at automating the Eye of Amazoo to perform very specific delivery tasks. Director Hayzos is pleased with your progress.
These tiny programs have only presented the smallest glimpse of what programs and algorithms can do. The chapters to come will present you with many more possibilities! Good luck.