Showing posts with label Answer Key. Show all posts
Showing posts with label Answer Key. Show all posts

Sunday, August 10, 2014

Solutions: Modular Programming with Squares on Pro-Bot

This is a subset of solutions for the assignment Modular Programming with Squares. This is just one way of coding the solutions, there are multiple correct solutions for the same.


Breaking Down Squares


1.  The shape is a square. It can drawn using the code:
Rpt 4 [    
Fd 12
Rt
]




2.  The above square needs to be divided into two equal parts. You can do this with a horizontal or vertical line across the middle or divide the square along the diagonal. The solution below divides the cake along the horizontal line
across the middle.
Rpt 4 [
Fd 12
Rt
]
Fd 6
Rt
Fd 12

3.  The square now needs to be divided into quarters. Two possible solutions, along the diagonals or using horizontal & vertical lines. The solution below divides the cake along the horizontal & vertical lines.
Rpt 4 [
Fd 12
Rt
]
Fd 6
Rt
Fd 12
Bk 6
Lt
Fd 6
Bk 12

4.  Here is another way to divide the cake into quarters, along the diagonals.
Rpt 4 [
Fd 12
Rt
]
Rt 45
Fd 17
Lt 135
Fd 12
Lt 45
Bk 17

5.  You need to divide the 12 x 12 cake into 9 equal pieces in this case.  Each slice is going to be 4cm x 4 cm.  Here is a solution using Nested Loops.
Rpt 4 [
Fd 12
Rt
]
Rpt 2 [
Rpt 2 [
Fd 4
Rt
Fd 12
Bk 12
Lt
]
Fd 4
Rt
]


Building Up with Squares as the Basic Building Blocks


1.  The square can be drawn using the code:
Rpt 4 [
Fd 6
Rt
]

2.   Here is the code for the rectangle drawn without using Nested Loops:
Rpt 4 [
Fd 6
Rt
]
Fd 6
Rpt 4 [
Fd 6
Rt
]
Fd 6
Rpt 4 [
Fd 6
Rt
]

3.  As seen from the code above, there is a repeating pattern. After drawing each square, you need to move to the starting position for the next square. The above code can be rewritten using Nested Loops as:
Rpt 3 [
Rpt 4 [
Fd 6
Rt
]
Fd 6
]


4. & 5.  To draw the large square that is double the size of the small square, different techniques can be employed. The easiest is to start from the midpoint of the figure. Each time, draw the small square and then turn 90 degrees to the right. Here is the code that uses Nested Loops.

Rpt 4 [
Rpt 4 [
Fd 6
Rt
]
Rt
]


Solutions to the Hopscotch figure:















Rpt 3 [      // Start drawing the rectangular part of the hopscotch from bottom left corner
Rpt 4 [
Fd 6
Rt
]
Fd 6
]
Rt             // Here, you want to try and get to the midpoint of the large square
Fd 3         // 3 cm from the top of the rectangle to the midpoint of large square
Lt
Fd 6         // You have reached the midpoint of the large square now
Rpt 4 [     // Now draw the large square using the previously written code for the same
Rpt 4 [
Fd 6
Rt
]
Rt
]

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


Wednesday, July 30, 2014

Solutions: Procedures: Revisiting Squares

The Procedures in Pro-Bot are pre-named from Proc1 to Proc32.


1.  Let's write the program for the square and store it in a procedure called Proc1. Access the New Proc or Edit Proc options from the Menu button to access the procedures and  choose Proc1. Here's what Proc1 might look like:

// Remember that you would see Proc1 as the first line on the screen here, not Main.

   Rpt 4 [
   Fd 6
   Rt
   ]


// To run this Procedure, go back to Main by clicking on the Menu button. Call Proc1 from Main using the Proc key and the number 1 on the control pad. Then press Go and watch your Procedure execute.



2.   Here is one way to use Proc1 from the above program to draw the stack of squares.

     Rpt 3 [
     Proc 1
     Fd 6
     Rt
     Fd 6
     Lt
     ]





3.   To draw the coaches for the train using Proc1, you could use the following code:
   
    Rpt 3 [
    Proc 1
    Rt
    Fd 8
    Lt
    ]

Solutions: Debugging

1.  The program to trace the number 2 has bugs in instructions & data.

   Fd 6
   Rt
   Fd 6
   Rt
   Fd 6
   Rt          //Wrong instruction, Rt instead of Lt
   Fd 6
   Lt
   Fd 12    //Wrong data, 12 cm instead of 6 cm

Here is the program with the bugs fixed:

   Fd 6
   Rt
   Fd 6
   Rt
   Fd 6
   Lt      
   Fd 6
   Lt
   Fd 6  




2.  The missing square bracket for the Rpt instruction is a very common bug.

    Rpt 2 [
    Fd 6
    Lt
    Rpt 3 [
    Fd 6
    Rt
    ]
    Rt
    Rt
    // The closing square bracket is missing as the last instruction here.
    // Without it, the outer loop executes only once, not twice as intended.


Here is the program with the bugs fixed:

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



3.  A stack of squares, using a Nested Loop:  The given program has bugs in data, punctuation (missing square bracket) and missing instructions.

    Rpt 2 [     // Wrong data, need 3 squares not 2
    Rpt 5 [
    Fd 6
    Rt
    ]
    // Missing a few instructions here, as well as a closing square bracket for the outer loop.


Here is the program with the bugs fixed:

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



4.  A square of sides 6 cm divided into two equal parts: The given program has wrong data and wrong instructions.
   

    Rpt 4 [
    Fd 6
    Rt
    ]
    Fd 2     // Wrong data, need to move 3 cm to get to the midpoint 
    Rt
    Bk 6    // Wrong instruction, need Fd 6

Here is the program with the bugs fixed:
    Rpt 4 [
    Fd 6
    Rt
    ]
    Fd 3     
    Rt
    Fd 6    



5.  Three squares stacked on top of each other. 

    Rpt 2 [     // Wrong data: need 3 squares, so repeat 3
    Rpt 5 [
    Fd 6
    Rt


    ]
    // Missing instructions here
    ]

Here is the program with the bugs fixed:
    Rpt 3 [     
    Rpt 5 [
    Fd 6
    Rt


    ]
    Lt
    ]

Tuesday, July 29, 2014

Solutions: More Practice with Nested Loops in Pro-Bot

Here is a set of solutions to draw the given patterns using Nested Loops in Pro-Bot. Please keep in mind that this is just a subset of the possible solutions, there can be many depending on the start point and the direction in which Pro-Bot is facing.


1.  Assuming that you start the figure from the leftmost corner at the bottom, here is one way to write the program:


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




2.  Assuming that you start the figure from the leftmost corner, here is one way to write the program:

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


3.  Assuming that you start the figure from the leftmost corner, here is one way to write the program:

     Rpt 2 [
     Rpt 3 [
     Fd 6
     Rt
     ]
     Bk 6
     Rt
     ] 

Solution: A Train using Nested Loops

1.  Assume we start drawing the train from the leftmost bottom corner, with Pro-Bot facing forward.

Here is the code for the engine:

  Fd 6
  Rt
  Fd 2
  Lt
  Fd 3
  Rt
  Fd 2
  Rt
  Fd 3
  Lt
  Fd 6
  Rt
  Fd 6
  Rt
  Fd 10
  Bk 12
  Rt

At this point, the engine is done and the Pro-Bot is ready to start drawing the coaches. The 3 coaches are similar, which means we can use Nested Loops for drawing them. Here is the code for the train with 3 coaches and the connectors:

  Rpt 3 [           // the 3 here refers to the number of coaches
  Rpt 3 [           // the 3 here refers to the 3 sides of the square that forms a coach
  Fd 6
  Rt
  ]
  Fd 6
  Bk 8
  Rt
  ]



2.  To draw the train with 5 coaches, the only change required is to change the 3 in the outer loop to 5. The code for the engine remains the same. The code for the coaches is now:

  Rpt 5 [           // the 5 here refers to the number of coaches
  Rpt 3 [           // the 3 here refers to the 3 sides of the square that forms a coach
  Fd 6
  Rt
  ]
  Fd 6
  Bk 8
  Rt
  ]



3.  To draw the train with 20 coaches, the only change required is to change the number in the outer loop to 20. Everything else remains the same.

  Rpt 20 [         // the 20 here refers to the number of coaches
  Rpt 3 [           // the 3 here refers to the 3 sides of the square that forms a coach
  Fd 6
  Rt
  ]
  Fd 6
  Bk 8
  Rt
  ]

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