CEMC Banner

Problem of the Week
Problem B and Solution
Coding Figures

Problem

Ayanna writes programs using the following commands that direct her robot to draw shapes.

Command Explanation
Pencil down Puts the pencil in position to draw as the robot moves
Move Moves the robot a given distance forward
Turn CW Rotates the robot one quarter turn (\(90\degree\)) clockwise
Turn CCW Rotates the robot one quarter turn (\(90\degree\)) counter clockwise
  1. For each program, follow the code to draw the shape. You may find grid paper helpful.

    1. Pencil down 
      Repeat 4 times
         Move 5 cm
         Turn CW
      End
    2. Pencil down
      Move 4 cm
      Turn CCW
      Move 2 cm
      Turn CW
      Move 2 cm
      Turn CW
      Move 6 cm
      Turn CW
      Move 6 cm
      Turn CW
      Move 4 cm
      End
  2. Write a program that would direct Ayanna’s robot to draw the given rectangular U-shape.

    The outer part of the U-shape has two vertical sides (left and right) that are each 5 cm long and a horizontal bottom side that is 10 cm long. The horizontal distance between the left sides of the inner and outer parts of the U-shape is 2 cm. The same is true for the right sides. The vertical distance between the bottom sides of the inner and outer parts of the U-shape is 2 cm.

Solution

  1. For each program, the shape is shown on \(1\) cm grid paper with an arrow indicating the initial direction of the robot. Note that for part (i), the shape will look the same regardless of the initial direction. However for part (ii), the shape will be rotated depending on the initial direction.

    1. The shape is a square with side length 5 units. An arrow points to the right from the top-left corner of the square.

    2. The shape is composed of a larger rectangle with a smaller square placed along its top side so that the right sides of the rectangle and square line up. The rectangle has length 6 units, running horizontally, and width 4 units. The square has side length 2 units. An arrow points to the right from the top-left corner of the rectangle.

  2. We start by determining the length of each side of the shape. We do this by drawing the shape on grid paper, as shown.

    To draw the U-shape starting at the top-left corner of the grid paper, move down 5 units, right 10 units, up 5 units, left 2 units, down 3 units, left 6 units, up 3 units, then left 2 units to arrive back at the top-left corner.

    There are several different programs that can be written to direct Ayanna’s robot to draw the given shape, depending on the robot’s starting position and direction. In the following program, the robot starts in the bottom-left corner, facing to the right.

    Pencil down
    Move 10 cm
    Turn CCW
    Move 5 cm
    Turn CCW
    Move 2 cm
    Turn CCW
    Move 3 cm
    Turn CW
    Move 6 cm
    Turn CW
    Move 3 cm
    Turn CCW
    Move 2 cm
    Turn CCW
    Move 5 cm
    End