CS1321 Fall 2002
Homework 13

Due before 8 a.m. Friday, Oct. 19, 2001


Instructions:

Note:


Problem 1

Using the dir.ss teachpack from problem 16.3.1, write a program called dir-depth. It should consume a directory structure (as created by the dir.ss function create-dir) and return the depth— the longest path from the highest level to the lowest level— of the directory is. A directory with no subdirectories has a depth of 1.

Fig. 1

Your program should be called in the following manner:

(dir-depth <directory>)

If dir-depth were to consume the directory created by dir.ss that represented the folder "fonts" in Fig. 1, it should return 6. When passed the directory that represents the folder "cm" in Fig. 1, it should return 2.

A sample directory is being provided for testing and examples purposes. Download this sample directory into an empty fold/directory on your computer and unzip the the provided zip file. You should see a directory tree that resembles the picture shown in Fig. 2.

Fig. 2

NOTES

Problem 2

Similar to problem 17.3.1, write a function called list-pick. The function will consume a non-negative integer and a list. The function will return the nth position element out of the list, starting from the left most element in position zero of the list. If the list is too short for there to be an nth element, your function should return the symbol 'ERROR.

Your function will be called in the following manner:

(list-pick <number> <list>)

NOTES

The use of the list functions length and list-ref is prohibited. You will receive a zero for this problem if the length or list-ref functions are used.


Problem 3

Write a function called merge-even that will consume two list of integers (called list1 and list2 for discussion purposes). The function will go through list1 and list2 alternately taking even numbers from each of the list. The function will return a list of even numbers alternating between those found in list1 and list2. The process by which the numbers are selected are outlined bellow. If one list runs out of numbers before the other, the remaining numbers of the list which still contains numbers should continue to be processed.

PROCESS FOR SELECTING NUMBERS
  1. The first even number from list1 should be collected first.
  2. The first even number from list2 should be collected next.
  3. Step 1 and 2 should be continued until all the even numbers have been processed.

Your function will be called in the following manner:

(merge-even <list1> <list2>)

EXAMPLE

>(merge-even (list 1 3 5 6 -1 0 9 10) (list -2 4 8))

(list 6 -2 0 4 10 8)

>(merge-even (list 3 19 21 99 317) (list 11))

empty

NOTES

For this problem the predicate even? may be used.


(Parts of this assignment were taken from HtDP Section 14.4, and are the work of Felleisen, Findler, Flatt and Krishnamurthi. However, modifications have been made by the College of Computing, Georgia Tech; for educational purposes, for its introductory CS class.)