8.3
8.3.1 Placement Assignments
All the reading is from How to Design Programs, second edition.
8.3.2 Placement 1
8.3.2.1 Language and Software
For the placement process, you will be using the Racket programming language. Follow the link to download Racket. Installing it will also install the DrRacket programming environment, in which you can write and run your programs. The first part of the reading (see below) explains how to use DrRacket.
For the following assignment, you must use Racket’s Beginning Student language. Go to the Language menu, select Choose Language, and pick the language from the Teaching Languages section.
8.3.2.2 Questions
If you have questions, you can use our Piazza board. Please do not post answers or ask questions in a way that reveals your answers (for this and all future assignments). Read the policy on Honesty and Sharing: you’re responsible for adhering to it.
If you have prior programming experience, you may find this assignment quite easy. That’s because the assignments are designed so even students who haven’t had access to a computing course before can still have a fair shot at trying out. The assignments will grow in complexity, so you may well find yourself wanting to use Piazza later.
8.3.2.3 Library
(require 2htdp/image)
8.3.2.4 Reading
Read the Prologue of HtDP 2/e. You won’t need all the content of this part to do the work below (the first portion, through the “Arithmetic and Arithmetic” section, should suffice), but from the next assignment onward you will be defining functions and using conditionals (covered in the rest of the part), so you may find it useful read ahead.
If you want to learn more about Racket’s support for images, see the Quick Introduction.
If you are new to programming: people learn programming by actually writing programs and running them. As you read, type in the code in the document, see how it works, change it a little and see what happens. Actually trying the code in the assigned reading will be essential for you to get comfortable with the material. Do not passively “read” the material: you will get far less out of it than you imagine!
8.3.2.5 Task
Vietnam
Chile
Suriname
Saint Lucia
Turkey
You should create these flag images using the Racket image primitives (for rectangles, stars, etc.), not by finding the images and pasting them in. You are, however, welcome to use a Web search to figure out what the flags look like.
You may pick the dimensions of your flag, but please make it large enough for us to see (with a width of at least 100), but preferably not so large that we need to scroll a lot to see them all.
For maybe the only time this summer or during the semester, we will not judge you on absolute correctness (e.g., checking whether you got the precise ratios of the different parts right). We’re going to visually eyeball it for general adherence. Of course, feel free to geek out on the vexillological details as much as you wish!
8.3.2.6 Turnin
Please write a series of expressions in a single file such that, when the file is Run, the flags appear in the interactions area. If you do use define to give them names, make sure to use these names so that the criterion above is met.
Please name your file p1.rkt (“papa-one-dot-romeo-kilo-tango”). Failure to use the correct name or otherwise follow these instructions may result in zero credit. (Note: Google Drive will automatically rename your file(s) to include your name. This is fine.)
Upload your file here. You will need to be logged into the Google@Brown domain to upload: it will not work with a regular Google (…@gmail.com) account.
8.3.3 Placement 2
8.3.3.1 Language
For the following assignment, you must use Racket’s Beginning Student language. Go to the Language menu, select Choose Language, and pick the language from the Teaching Languages section.
8.3.3.2 Library
(require 2htdp/image)
You may also find some string functions useful.
8.3.3.3 Reading
Read Part 2 of HtDP 2/e, specifically chapters 8 and 9 through 9.1 (you don’t need to go further).
If you find something unfamiliar (e.g., the material references if), note that we skipped reading Part 1 so you may need to peek in there to look it up.
8.3.3.4 Task
Define the following functions. Even if you think they correspond to a function that already exists, write it yourself. We’re testing your ability to program, not to read documentation!
score-by-length :: List-of-strings -> Number
Consumes a list of strings that represents words. Produces the sum of the lengths of these words. (Imagine you’re writing a game based on words, and this is a scoring function. We’ll return to this theme.)
overlay-all :: List-of-images -> Image
Consumes a list of images and overlays them, with earlier images in the list over later ones. Use a 10x10 solid white rectangle for the base case.
Note: Image equality is an imperfect art. Images that visually appear identical may in fact be very slightly different, causing a test to fail.
bar-graph :: List-of-numbers -> Image
The numbers in the list represent heights of bars in a bar graph (assume they have already been scaled and reflect the desired heights). Generate a bar graph where each bar is a black solid 10px rectangle and successive bars are adjacent (use beside/align). Don’t have spaces between the bars. Use a 1x1 solid white rectangle for the base case.
You can assume that all the numbers are non-negative.
is-in? :: Any List-of-any -> Boolean
Consumes a value and list of values and determines whether the former is anywhere in the latter: returns #true if it is and #false otherwise.
Use equal? for comparison.
words-to-sentence :: List-of-strings -> String
Consumes a list of strings that represent words. Concatenate these strings with a space between every pair of words.
Write this function explicitly. You may not use any built-in string functions other than string-append.
8.3.3.5 Work Expectations
From this assignment onward, for the rest of the placement and the course, you will be graded on both the quality of your code and the correctness of your answers. The latter will be (mostly) graded by computer, so it’s vital you follow the problem specification exactly. The former will be (mostly) graded by hand, and we will look for how well you have presented the parts expected by the Design Recipe. Both parts are equally important.
8.3.3.6 Turnin
Please turn in a single file that 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. Please name your file p2.rkt. (Note: Google Drive will automatically rename your file(s) to include your name. This is fine.)
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.
8.3.4 Placement 3
8.3.4.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.3.4.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.3.4.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.3.4.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.3.4.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.
8.3.5 Placement 4
8.3.5.1 Goal
Functional programmers don’t actually spend all day writing recursive functions over lists. Rather, they use so-called “higher-order” functions, which are functions that consume other functions, to do that kind of work. That is, in functional programming, a loop is just a function, and different kinds of loops correspond to different kinds of higher-order functions. In this assignment you will learn about some of these “looping functions”.
There is also a second part [Learning by Contributing] to this assignment. Please see below.
8.3.5.2 Language
For the following assignment, you must use Racket’s Intermediate Student with lambda language. Go to the Language menu, select Choose Language, and pick the language from the Teaching Languages section.
8.3.5.3 Library
map
filter
foldl
foldr
andmap
ormap
You may also use any library function you were permitted to use on prior assignments, particularly in Placement 3.
8.3.5.4 Reading
14.1
14.2
14.4
15.1
15.4
16.1
16.2
16.5
8.3.5.5 Task
Define the same functions as in Placement 3. However, you are not allowed to use explicit recursion; you must use one of the functions listed in Library in its stead. You are of course welcome to write helper functions.
You are welcome to reuse anything appropriate that you wish from your Placement 3 submission, e.g., purpose statements and tests. You do not need to write templates.
We do expect you to do a thorough job on testing, building on the feedback you received for Placement 3.
Note that unique is a bit challenging and it’s okay if you can’t complete it after you’ve spent a while trying.
8.3.5.6 Turnin
You will again turn in two files.
One file, named p4-code.rkt, contains the five functions required above (it can contain any other helper definitions you like as well). The functions must be named exactly as decribed and must take parameters exactly as described. (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.
8.3.5.7 Learning by Contributing
We have added another part to Placement 4’s task. It’s based on Contributing Student Pedagogy, which enhances learning. It will also help us gauge what you’ve struggled with, helping us improve future versions of this class.
Please do this task after you have completed and submitted your assignment. (It will not require any changes to the files you turned in.)
Write a small program (please pay attention to the format), intended for your fellow students. Don’t include a purpose statement or give it a meaningful name and certainly do not include any tests! For brevity, you can also leave out any data definitions already seen in class. For most programs, you can include just executable code and, if you think it helps, a contract.
For this part, you are welcome to run it in DrRacket to make sure it doesn’t contain syntax errors, etc. You can also use it to see whether it produces the output you expect, but even if it does not—
especially if it does not— please submit it! But please don’t paste in your homework solutions. Predict the output of programs written by your fellow students.
For this part, you should not run the program in DrRacket. However, you should make a copy of the program and, after you are done with all the programs you are assigned, run each of them to compare your predicted answer against the true answer. If you don’t understand why one of them produced the answer it did, ask us privately on Piazza.