Exercise 6: Thinking about second tasks

Thinking about second tasks

Well, we already know how to create procedures, but why would we want to create them? Some possible answers:

  • in order to simplify code, writing things we will do many times, only once and in only one place;
  • in order to write less, since us programmers are a little lazy;
  • in order for the purpose of our program to be more comprehensive to humans beings, as we saw in the example of DrawBlackSquareSide3. For this, it is essential to think good names, but neither too long (DrawABlackSquareOfWidth3AndOfLarge3), nor too short (DraBlaSqu3), and above all that they clearly state which effect our procedure makes;
  • in order to communicate the strategy we consider to solve our problem; and as a consequence of all this: in order to write more powerful programs.

During next exercises, we will write a better version of DrawBlackSquareSide3, dividing every part of the program in smaller procedures.

To do this, we will suggest the following strategy: build the square like three lines of three stones, one on top of the other.

It is obvious we will need a command to draw a line, so let's start from there.

Write a procedure DrawBlackLine3 which, like its name shows, “draws a line” dropping 3 black consecutive stones to the East.

Note: From now on, unless the contrary is indicated, the “program” is done by us. So you just have to write the procedure.

Give me a hint!

You may have to make some effort in order to “see the line”, but basically what we are asking to do is to drop three black stones, one next to the other, to the East, like that:

GBB/1.0 size 3 3 cell 0 0 Negro 1 cell 1 0 Negro 1 cell 2 0 Negro 1 head 2 0

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