Showing posts with label Solution. Show all posts
Showing posts with label Solution. Show all posts

Thursday, July 31, 2014

Solutions: Art with Pro-Bot - A Soccer Game

The soccer game picture is a follow-up to the "Art with Pro-Bot: A Dancing Robot" exercise, with one of the figures being the exact same as the Dancing Robot and the other being its mirror image.


Let's name the figure on the left as Team A and the one on the right as Team B. You would recognize from the figure that both Team A and Team B share some parts in common, such as the head and the neck. So, it's easier for the programmer to write the code for these parts just once and store it as a procedure; it can then be used multiple times. 

// Proc 1 - procedure for the neck and head


Fd 1
Lt
Fd 1
Rt
Rpt 3 [
Fd 2
Rt
]
Fd 1





Team A:  


// Program written in Main and using the above procedure. The Start point is marked in the figure.


Rpt 4 [
Fd 10
Bk 4
Rt
]
Fd 3
Lt
Proc 1


Team B:


// Program written in Main and using the above procedure. The Start point is marked in the figure.


Rpt 4 [
Fd 10
Bk 4
Lt
]
Fd 3
Rt
Proc 1


Tuesday, July 29, 2014

Solutions: Art with Pro-Bot - A Dancing Robot

The picture of the Dancing Robot consists of 2 main parts - the body and the head, both of which are squares and can be drawn using Repeat Loops. The interesting part is that the limbs of the robot can also be drawn as part of the Repeat Loop for drawing the body.




Let's look at the code for drawing the body of the robot first. Please keep in mind that depending on the starting point and the direction in which Pro-Bot is facing, you can have different ways of drawing this figure.


Here is one way of drawing it, refer to the figure on the right for the Starting point.

    Rpt 4 [
    Fd 10       // body + limb = 10 cm
    Bk 4          
    Rt        
    ]




Now, let's try to draw the neck and the head of the robot. Again, the following code is just one of the possible solutions.

Starting from the neck and going up,

    Fd 1          // 1 cm long neck
    Lt
    Fd 1
    Rt
    Rpt 4 [      // Repeat loop to draw the square for the head
    Fd 2
    Rt
    ]
 

Combining the two pieces of code above, we have the final program to draw our dancing robot:
 
    Rpt 4 [      // Start by drawing the body of the robot
    Fd 10    
    Bk 4          
    Rt        
    ]
    Fd 3         // After drawing the body, get to the start point for drawing the neck
    Lt
    Fd 1          // Draw the 1 cm long neck
    Lt
    Fd 1
    Rt
    Rpt 4 [      // Draw the square for the head
    Fd 2
    Rt
    ]



Solutions: Art with Pro-Bot - Snails

Let's create four procedures for the squares of sides 2 cm, 4 cm, 8 cm and 12 cm. We could store them in Proc 1, Proc 2, Proc 3 and Proc 4.


Here is one way of writing these procedures:

// Proc 1 - procedure for drawing 2 cm side square
Rpt 4 [
Fd 2
Rt
]


// Proc 2 - procedure for drawing 4 cm side square
Rpt 4 [
Fd 4
Rt
]


// Proc 3 - procedure for drawing 8 cm side square
Rpt 4 [
Fd 8
Rt
]


// Proc 4 - procedure for drawing 12 cm side square
Rpt 4 [
Fd 12
Rt
]



Next, we shall use the above procedures to draw the snails. Keep in mind that this is just a subset of the possible solutions. Both the procedures as well as the following programs can be written in multiple ways.

Program for the small snail as written from Main:


Proc 1
Rt
Fd 4
Lt
Proc 2
Rt
Fd 1
Lt
Proc 1


Program for the large snail as written from Main:


Proc 2
Rt
Fd 8
Lt
Proc 4
Rt
Fd 2
Lt
Proc 3
Rt
Fd 2
Lt
Proc 2



Solutions: Art with Pro-Bot - Snowmen

Let's first write the programs for the squares of sides 6 cm, 4 cm and 2 cm.  We shall store these are three different procedures, say in Proc1, Proc2 and Proc 3.

Here is one way of writing the programs:


Proc 1      // procedure for 6 cm side square
Rpt 4 [
Fd 6
Rt
]


Proc 2      // procedure for 4 cm side square
Rpt 4 [
Fd 4
Rt
]


Proc 3      // procedure for 2 cm side square
Rpt 4 [
Fd 2
Rt
]



Now let's draw the small snowman using the above procedures. From Main, the program shall be written as:


// Program for the Small Snowman


Proc 2
Fd 4
Rt
Fd 1
Lt
Proc 3


You can use the above procedures for drawing the large snowman as well. From Main, the program for the large snowman can be written as:


// Program for the Large Snowman


Proc 1
Fd 6
Rt
Fd 1
Lt
Proc 2
Fd 4
Rt
Fd 1
Lt
Proc 3









Solutions: A Maze Using Repeat Loops in Pro-Bot

1.  Assuming that you start at the leftmost corner and facing forward, here is a possible solution for the maze given in the figure:


Rpt 3 [
Fd 12
Rt
]
Fd 2
Rt
Rpt 3 [
Fd 8
Lt
]
Fd 2
Lt
Rpt 3 [
Fd 4
Rt
]



2.  Assuming that you start at the leftmost corner and facing forward, here is a possible solution for the maze given in the figure. The program is same as the one above, with an addition of two more instructions at the end, to draw the solid line at the bottom of the maze.


Rpt 3 [
Fd 12
Rt
]
Fd 2
Rt
Rpt 3 [
Fd 8
Lt
]
Fd 2
Lt
Rpt 3 [
Fd 4
Rt
]
Bk 2
Fd 10


Solutions: Repeat Loops for Drawing Squares with Pro-Bot

Let’s write down the code for drawing a square with sides 6 cm each, using Pro-Bot. 

Assuming you start at the left most bottom corner and you are facing forward, the square can be drawn using the following code:


  

   Fd 6
   Rt
   Fd 6
   Rt
   Fd 6
   Rt
   Fd 
   Rt     // optional




Do you see a repeating pattern in the code?

Circle the part in the code that repeats. Circle the corresponding part in the picture as well.

Write down the part of the code that repeats.

   Fd 6
   Rt


How many times do we repeat the pattern?

   4 times

Can you now rewrite the code for the above square using a Repeat loop?

   Rpt  4  [                                 
   Fd 6
   Rt
   ]


How many lines of code were there in your first version, without the Repeat Loop?

    8 lines

How many lines of code are there in your new version using the Repeat Loop?

    4 lines

By how much did you reduce the number of lines of code in your new version?

    4 lines

Can you now write a program for Pro-Bot to draw a square of sides 10 cm using a Repeat Loop?

   Rpt  4  [                                 
   Fd 10
   Rt
   ]



Part of a Square

The following figure looks like a square with one side of it removed. Each side measures 6 cm. Can you write a program for Pro-Bot to draw it using a Repeat Loop? 

Assuming you start at the left most bottom corner and you are facing forward, the pattern can be drawn using the following code:



Rpt 3 [
Fd 6
Rt
]















Monday, July 28, 2014

Solutions: Repeat Loops in Pro-Bot Assignment 1

Here is a set of solutions to the Repeat Loops Assignment 1.  The Start point is marked in each figure. Pro-Bot is assumed to be facing forward at the starting position.




1.  Repeat Loops Pattern 1

     Rpt 3 [
     Fd 6
     Rt
     Fd 6
     Lt
     ]



2.  Repeat Loops Pattern 2

 
     Rpt 2 [
     Fd 6
     Rt
     Fd 6
     Rt
     Fd 6
     Lt
     Fd 6
     Lt
     ]



3.  Repeat Loops Pattern 3

   
     Rpt 3 [
     Fd 6
     Rt
     Fd 6
     Rt
     Fd 12
     Lt
     Fd 6
     Lt
     Fd 6
     ]

Solutions: Letters of the alphabet

Here is a set of solutions for the "Letters of the alphabet" assignment. Do keep in mind that this is just a subset of possible solutions. Depending on the start point chosen and the direction in which Pro-Bot is facing, you can have multiple solutions for each figure.

For each letter, I have marked the starting point in the figure on the right. The Pro-Bot is assumed to face forward at the starting point in each case.

All dimensions are in cm.


Letter T:
Fd 12
Bk 6
Rt
Fd 12

Letter I:
Fd 12
Bk 6
Rt
Fd 12
Rt
Fd 6
Bk 12

Letter J:
Fd 12
Bk 6
Rt
Fd 12
Rt
Fd 6

Letter F:
Fd 6
Rt
Fd 6
Bk 6
Lt
Fd 6
Rt
Fd 12

Letter E:
Fd 12
Rt
Fd 6
Rt
Fd 6
Bk 6
Lt
Fd 6
Rt
Fd 12

Solutions: Tracing Digital Numbers

Here is a set of solutions for the "Tracing Digital Numbers" assignment. Do keep in mind that this is just a subset of possible solutions. Depending on the start point chosen and the direction in which Pro-Bot is facing, you can have multiple solutions for each figure.

For each digital number, I have marked the starting point in the figure on the right. The Pro-Bot is assumed to face forward at the starting point in each case.

All dimensions are in cm.

Number 1:
Fd 12

Number 2:
Fd 6
Rt
Fd 6
Rt
Fd 6
Lt
Fd 6
Lt
Fd 6

Number 3:
Fd 6
Lt
Fd 6
Rt
Bk 6
Fd 6
Lt
Fd 6
Lt
Fd 6

Number 4:
Fd 12
Bk 6
Lt
Fd 6
Rt
Fd 6

Number 5:
Fd 6
Lt
Fd 6
Lt
Fd 6
Rt
Fd 6
Rt
Fd 6

Number 6:
Fd 6
Lt
Fd 12
Lt
Fd 6
Lt
Fd 6
Lt
Fd 6

Number 7:
Fd 12
Lt
Fd 6

Number 8:
Fd 6
Lt
Fd 6
Rt
Bk 6
Fd 6
Lt
Fd 6
Lt
Fd 6
Lt
Fd 12

Number 9:
Fd 6
Lt
Fd 12
Lt
Fd 6
Lt
Fd 6
Lt
Fd 6

Number 0:
Fd 6
Lt
Fd 12
Lt
Fd 6
Lt
Fd 12