Question
Robot lives in the world on the next slide. We want Sam to double the number of beepers on a corner in the world. Provide
Robot lives in the world on the next slide. We want Sam to double the number of beepers on a corner in the world. Provide the algorithm needed to double the pile of beepers. You can assume the following:
There is a finite number of beepers on the corner directly in front of Sam
has an infinite number of beepers in his bag
robot understands the following commands
move() takes one step forward
turn() turns left 90 degrees
pickUpBeeper() picks up 1 beeper from the floor and puts it in the bag
putBeeper() puts one beeper on the floor from the bag
repeat X times / End statements between the X and the End will be repeated X times
while ? / End (statements between the ? Condition and the End will repeat as long as the ? Condition returns true.
robot knows how to do the following tests
beepersPresent() returns true if there is at least 1 beeper on the spot Sam is standing
Lab problem 2 requirements
On each of the avenues, there is a tower of beepers of an unknown height, although some avenues (such as 7th in the example photo) may be empty.
Sams job is to collect all beepers in each of these towers and put them back down on the easternmost corner of 1st street (bottom right of his world), then return to his starting position.
Sam does not have any beepers in his pouch when he starts.
See next slide for an after photo
What sam knows
Test | Opposite | What it Tests |
frontIsClear | frontIsBlocked | Is there a wall in front of Sam? |
leftIsClear | leftIsBlocked | Is there a wall to Sams left? |
rightIsClear | rightIsBlocked | Is there a wall to Sams right? |
beepersPresent | noBeepersPresent | Are there beepers on this spot? |
beepersInBag | noBeepersInBag | Are there beepers left in Sams bag? |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started