8.6 Placement 3
8.6.1 Language
For the following assignment, you must use Racket’s Beginning Student with List Abbreviations language. Go to the Language menu, select Choose Language, and pick the language from the Teaching Languages section.
8.6.2 Library
In Placement 2 you defined the function is-in?. This is built into Racket with the name member. You may use member from now on.
We will also be using characters, which are the elements of strings. Characters are written with a #\ prefix: e.g., #\c, #\s. You can turn strings into lists of characters and vice versa using string->list and vice versa with list->string.
Note that some functions in this assignment would benefit from creating a helper function to handle a complex sub-task.
8.6.3 Reading
Read Part 2 of HtDP 2/e, specifically chapter 10.1. You can read past it if you feel the need as you’re doing the assignment.
If you find something unfamiliar, recall that we skipped reading Part 1 so you may need to peek in there to look up something.
8.6.4 Task
Define the following functions.
elim-contains-char :: Char List-of-strings -> List-of-strings
Consumes a list of strings and produces a list of the same words, in the same order, excluding those strings that contain the given character.
valid-words :: List-of-strings List-of-chars -> List-of-strings
Consumes a list of words (represented as strings) and a list of letters (represented as characters). Produces the list of same words, in the same order, that contain only those letters. (Imagine a game where you have to assemble words with just the letters you have.)
For this assignment, ignore multiplicity: i.e., a word may contain more instances of a letter than the number of times the letter was present in the second parameter. Also, letters should be case-sensitive (e.g., #\A does not appear in "cat").
unique :: List-of-any -> List-of-any
Given a list of values, produces a list of the same values in the same order excluding duplicates. If a value is present more than once, its first instance stays and the remainder are discarded. Use equal? for comparison.
l33t :: List-of-strings -> List-of-strings
Consumes a list of words (represented as strings) and produces a list of the same words, in the same order, but where some of the letters have been replaced by characters that stand for numbers. Specifically, it turns #\A and #\a into #\4,Note that #\4 is a character, whereas 4 is a number. You can’t do arithmetic on the former or put the latter in a string. #\E and #\e into #\3, #\I and #\i into #\1, and #\O and #\o into #\0.
Note: The first letter of the name is the letter ‘l’ (Lima), not the number ‘1’ (One).
strip-vowels :: List-of-strings -> List-of-strings
Consumes a list of words (represented as strings) and produces the same list of words, except with each vowel (#\a, #\e, #\i, #\o, or #\u, or their upper-case equivalents) removed. (If a word consists of all vowels, it reduces to the empty string but is not removed entirely.)
Note: Be careful. There’s a simple, clean decomposition of tasks in this problem, but if you rush you may end up with a mess.
8.6.5 Turnin
This time you will turn in two files.
One file, named p3-code.rkt, contains the five functions named above (it can contain any other helper definitions you like as well). The functions must be named exactly as above and must take parameters exactly as above. (Note: Google Drive will automatically rename your file(s) to include your name. This is fine.)
In addition, make a copy of just the test cases for the
required functions—
Failure to follow any of these instructions may result in zero credit.
Upload your file here. You will need to be logged into the Google@Brown domain to upload.