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 "Advanced Student Mode".
For all problems, you should read the words program and function to mean "program or group of programs," or "function or group of functions."
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)
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.
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
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.
(define (foo A B C)
(cond [(empty? c) empty]
[(A B (first C)) (foo A B (rest C))]
[else (cons (* 2 (first C)) (foo A B (rest C)))]
)
)
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).
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)
Your function must use the built-in Dr.Scheme function map to solve this problem.
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)
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.
Do a trace of merge-sort, in the same fashion as Problem 5 with the same list passed in as its initial argument.
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.