Exercise 3: Teaching the computer some tasks

Teaching the computer some tasks

As we explained in the square example, we can start making differences between two types of commands inside a program:

  • those that are defined by the language and are useful to express basic operations, such as Move, Drop and Grab. We call them primitive commands, or simply primitive;
  • and those that are defined by ourselves, which are useful to express more complex tasks. Like the name of this lesson suggests, these are the procedures.

When creating a procedure, we “teach” the computer to carry out a new task, which wasn't originally included in the language.

It would be impossible to write a language that includes EVERYTHING that we may want to do, wouldn't it?

Now it's your turn: write a procedure Drop3Green which drops 3 green stones in the current cell and a program which uses it.

Give me a hint!

If you don't know how to start, copy the code of the previous exercise and modify the parts you consider necessary.

procedure DrawBlackSquareSide3() {
  Drop(Black)
  Move(East)
  Drop(Black)
  Move(East)
  Drop(Black)
  Move(North)
  Drop(Black)
  Move(West)
  Drop(Black)
  Move(West)
  Drop(Black)
  Move(North)
  Drop(Black)
  Move(East)
  Drop(Black)
  Move(East)
  Drop(Black)
}

program {
  DrawBlackSquareSide3()
}

You must sign in before submitting your solutions

Oops, your solution didn't work

  • Check that your program does not have recursion or an infinite loop
  • Check that you have an internet connection
  • Wait a while and try again

We are processing you solution

Please press F5 if results are not displayed after a few seconds