CS1321 Fall 2002
Homework 14

Due before 8 a.m. Friday, Nov. 2, 2001


Instructions:

Note:


Problem 1

For each of the following function descriptions, write the contract needed for the Design Recipe
(NOTE: You do not need to write the entire design recipe, just the contract)

  1. A function named tween, that consumes a list and a function that consumes two items which produces a boolean. Tween should produce a list of numbers.

  2. A function named thwart, that consumes a list of lists and a function that takes in a list and produces a number. Thwart should return a list of numbers

  3. A function named tinker, that consumes a list of lists. Each list inside the outer list is made of a scheme item and a number. Tinker should also take in a list of functions-- each of which takes in a list and a number and produces a list. Tinker should return a list of items.

  4. Given the following DEFINITION section, write the contract:

NOTES


Problem 2

Do problem 21.1.1 out of the HtDP book. You only need to write the general abstraction function. You are expected to do a full design recipe for the abstracted function.

Your function should be named tabulate and will take two parameters: the function and n (in that order).


Problem 3

Write a function called double-list. It should take in a list of numbers and return a list of numbers. The returned list should contain all of the numbers in the original list doubled. Be sure to use good abstraction.

Your function will be called in the following manner:

(double-list <list>)

So the follow output would be returned for the call below:

> (double-list (list 3 8 9 10))
(list 6 16 18 20)

NOTES


Problem 4

Write a function called convert-temp. It takes in a list of temperatures (measured in Celsius), a conversion formula, and returns the list converted to a new unit of measurement. The conversion formula taken in outlines how to convert from Celsius to the new unit of measurement. For example, a new temperature unit called Clarbs has been developed by some of the CS1321 TA's. The formula for converting from Celsius to Clarbs can be shown as

Clarb= (Celsius-32)/15 + (8 * (Celsius + 4))

Your function will be called in the following manner:

(convert-temp <list> <conversion-formula>)

The following calls will produce the output below:

> (convert-temp (list 35 37 0 100) C->Clarb)
(list 312.2 985/3 448/15 12548/15)

> (convert-temp (list 12 123 5 98) C->Clarb)
(list 380/3 15331/15 70.2 820.4)

> (convert-temp (list 12 123 5 98) Celsius->Fahrenheit)
(list 53.6 253.4 41 208.4)

NOTES


Problem 5

Do a trace in the fashion presented on page 366 of the quick-sort function from page 365 in the HtDP book Trace the function as if the initial call

(quick-sort (list  9  -2  57  12  17  8))

had been made.


Problem 6

Do a trace of merge-sort, in the same fashion as Problem 5 with the same list passed in as its initial argument.


Problem 7

a) Outline at least two ways in which merge-sort and quick-sort are similar.

b) Outline at least two ways in which merge-sort and quick-sort are different.


(Parts of this assignment were taken from HtDP, 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, as are necessitated for their introductory CS class.)