AP Computer Science A
Karel J. Robot Lab #5
Individual Problem Statements:
This lab explores instance data and data types
Karel should double the amount of beepers on a corner (located right in front of it). Assume that there is a finite number of beepers on the corner and karel starts with an infinite number of beepers in his beeper bag. Karel should create a second pile of beepers that doubles the amount of beepers present on the corner in from of it.
Initial State Final State
There is a menace in Karel’s world--an infinite pile of beepers! If Karel accidentally tries to pick up an infinite pile of beepers it is forever doomed to pick up beepers from the pile. The robot is standing outside of two rooms: one is to the west and one is to the east. Only one of these rooms has a pile of beepers that karel can pick. The other room has an infinite pile of beepers. To help the robot decide, Karel is currently standing on a pile of beepers. If the pile of beepers is even, the same room is on the east. If the pile of beepers is odd, the safe room is to the west. Write a program in which karel correctly enters the safe room and picks the entire pile of beepers.
Program Karel to go on a treasure hunt. The treasure is marked by a corner containing five beepers. Other corners (including the corner in which karel starts) contain clues, where each clue indicates the direction karel should proceed. Karel begins at the corner of 2nd Street and Second Ave. The clues are as follows: 1 beeper means karel should go north, 2 means east, 3 means south, 4 means west. Karel should follow the clues until it reaches the treasure corner where the robot should turn itself off. Below is a possible treasure hunt. You can assume that Karel starts on the corner of 2nd Avenue and 2nd Street
Karel has been tasked with “cleaning up” a voting ballot according to the following rules:
What does modular arithmetic allow you to do? How does it work with negative numbers?