PA3: FoneDrone
Categories:
less than a minute
The base case is when there is no direction to search in. Then, the only thing the Drone
has to do is check for the phone and return. Nothing could be easier than that. So, letting an X denote a space where the Drone
has already been, the following is a base case:
| X |
— —
X * X
— —
| X |
and the following is not:
| |
— —
*
— —
| |
Given this definition of the base case, to refine difficult cases you need to eliminate directions to search in, recurse, and move in the opposite direction. So what the refinement process needs to do is:
- Move forward, search, and move backward;
- Move right, search, and move left;
- Move backward, search, and move forward;
- Move left, search, and move right.
It’s important to note that there is no reason to keep track of where the Drone
has been and write code to return to the starting location.
The Drone
will return to the starting location because it always moves back to where it was.
Last modified January 14, 2024: added example setup_current for reference (d786ca9)