TURN IN THIS ASSIGNMENT USING WEBWORK!!!
Do this homework using DrScheme. (Save the file as a ".scm" file--that is, with a .scm extension.)
Your parameters must be in the same order as they are shown here. If you are unsure, ask your TA. You will lose credit otherwise.
Your functions should be named exactly as they are shown in each problem.
Follow the HW Skeleton, these homeworks will be autograded and must be in the specified format. You will lose credit otherwise.
Any submissions which don't execute cleanly (i.e. no errors when you click Execute) may receive a grade of zero.
If you do not submit a .scm file, you may receive a grade of zero.
Remember that you must be in "Intermediate Scheme".
For all problems, you should read the words program and function to mean "program or group of programs," or "function or group of functions."
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.
|
Your program should be called in the following manner:
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.
|
Section 16 of your HtDP book covers various models of directory trees that may help you better understand this problem.
Remember to do the analysis for any structures that are provided by the dir.ss teachpack there is no need to provided the define-struct commands given in the teachpack.
The help desk in Dr.Scheme can provide you with additional information on the dir.ss teachpack.
Exercise 16.3.1 shows how to enter the directory/folder name passed into the create-dir function in the dir.ss teachpack. Notice that double backslashes are used on computers running windows.
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>)
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.
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
- The first even number from list1 should be collected first.
- The first even number from list2 should be collected next.
- 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
For this problem the predicate even? may be used.