In the grid, the black squares represent obstacles to Cupid, who cannot go through them; nor can Cupid step outside the grid boundaries.
Let’s play with some pseudocode to guide Cupid’s path to the heart. The code will use the following instructions:
fly1: moves Cupid one square in
the current arrow direction
rotc: turns (rotates) Cupid \(90\degree\) clockwise
rotcc: turns Cupid \(90\degree\) counterclockwise
fly1
rotc
fly1
fly1
rotc
fly1fly1
rotc
fly1
rotcc
fly1Write pseudocode which guides Cupid to the heart.
We go through the pseudocode, moving Cupid as directed.
fly1: Cupid moves one square
eastrotc: Cupid turns southfly1: Cupid moves south one
squarefly1: Cupid moves south one
squarerotc: Cupid turns westfly1: Cupid moves one square
westFollowing this sequence of moves, Cupid ends up in the lower left square on the grid.
We go through the pseudocode, moving Cupid as directed.
fly1: Cupid moves one square
eastrotc: Cupid turns southfly1: Cupid moves south one
squarerotcc: Cupid turns eastfly1: Cupid moves east one
squareFollowing this sequence of moves crashes the code, since Cupid is attempting to move through an obstacle.
fly1
rotc
fly1
fly1
rotcc
fly1
fly1
rotcc
fly1rotc
fly1
fly1
rotcc
fly1
fly1
fly1
rotcc
fly1