map
and filter
to re-write some of the list functions we developed a
couple of weeks ago.
Assume that for each river, measurements of the river's pH and DO (dissolved oxygen) levels are available. Such measurements are taken at the confluence of the rivers (the point at which the tributaries converge). pH levels can range from 0 (most acidic) to 14 (most alkaline). The normal range for bodies of water are 6.5 - 8.5. DO is measured in parts per million (ppm), and can range (at sea level) from 0 ppm (the lowest amount of dissolved oxygen) to 12ppm (saturation point).
For this assignment, latitude and longitude can be expressed as whole numbers (0-90 for latitude, 0-180 for longitude) followed by a designation of north or south, east or west (so, for example, Worcester is at 42 N, 71 W).
lower-ph-than
that consumes a river system and a
number. The function produces a list of the names of each river in the given
system that has a pH value lower than the given pH.
healthy?
that consumes a river system and
produces a boolean. The function returns true if every river in the system
has a pH between 6.5 and 8.5, and a DO of at least 6ppm.
lower-all-ph
that consumes a river system and
produces a river system. The river system that is produced is the same as the original,
except that the pH of all the rivers in the system have been lowered
by 0.1.
The next problem is a little trickier than the preceding problems. We'll see how to solve this kind of problem on Monday (Feb 13). You won't have a problem like this one on Exam 2.
find-river
that consumes a river system and
the name of a river and produces the location (i.e. the latitude and
longitude) of the named river. You may
assume that a river with the given name exists in the river system.
ad
and
list-of-ad
from the given solutions to your DrRacket Definitions window.
Problems 8, 9, and 11 can be solved using filter. We'll see how to solve problem 10 on Monday.
count-political-ads
,
that has the following contract and purpose:
;; count-political-ads: list-of-ad -> number ;; consumes a list of ads and produces the number of ads in the list that are political(Hint: You may use the DrRacket built-in function called
length
that returns
the number of items in a list.)
primetime-ads
, that has the following contract and purpose:
;; primetime-ads: list-of-ad -> list-of-ad ;; consumes a list of ads and produces a list of all the ads occurring in primetime
politicians-sponsoring-ads
, that has the following contract and purpose:
;; politicians-sponsoring-ads: list-of-ad -> list-of-string ;; consumes a list of ads and produces a list of strings. The list that is produced contains the names of the politicians who have political ads ;; (it's OK if the resulting list contains duplicate names).
expensive-ads
, that has the following contract and purpose:
;; expensive-ads: list-of-ad number -> list-of-ad ;; consumes a list of ads and a number. The function produces a list of those ads for which the total ad cost exceeds the given number.
Using web-based turnin, turn in a single file containing all code and documentation for this assignment. Name your file according to the naming conventions for files. Make sure both partners' names and wpi login names appear in a comment at the top of the file.