recursion [Archive] - SpeedGuide.net Broadband Community

View Full Version : recursion


monkeyhead
04-27-02, 04:44 PM
The LOGO mini-language (intended to instruct novices in programming) manages robots on a screen. The robots traverse rectangular routes, with the following recursive definition.

(1) The empty list is an open route.
(2) Formation rules. If R is an open route, so are

------(a) R forward. (Go forward one step after doing R.)
------(b) R reverse. (Turn around 180 degrees; don’t move.)
------(c) R right. (Turn right 90 degrees; don’t move).
------(d) R left. (Turn left 90 degrees; don’t move.)

(3) If R is an open route, then R stop is a completed route.

(4) Nothing else is a route.


Question 1: Give a recursive specification for the total amount of turns, in degrees. (The rule for (3) is: If the route is of the form R stop, then report R.turns as the total amount.)

Question 2: Give a recursive specification for the total distance traversed.