Functional Problem Solving (CSC 151 2015F) : Assignments
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Taking Notes] [Rubric] [Remote Access]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Labs] [Outlines] [Readings] - [Examples] [Handouts]
Reference: [Setup] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Curtsinger (2015F)] [Davis (2013F)] [Rebelsky (2015S)] [Weinman (2014F)]
Misc: [Submit Questions] - [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)]
Assigned: Sunday, 4 October 2015
Due: The due dates for various tasks are as follows.
Important! This examination has an initial code file that you should copy and use as the starting point for your work.
This is a take-home examination. You may use any time or times you deem appropriate to complete the exam, provided you return it to me by the due date.
This examination has a prologue that must be completed by the Friday evening before the exam is due. The prologue is intended to help you get started thinking about the examination. The prologue is required. Failure to fill in the prologue by the designated time will incur a penalty of five points on the examination.
This examination has an epilogue that must be completed by the evening after the exam is due. The epilogue is intended to help you reflect carefully on the examination. The epilogue is required. Failure to fill in the epilogue will incur a penalty of five points on the exam.
There are seven problems on this examination. Each problem is worth the same number of points. Although each problem is worth the same amount, problems are not necessarily of equal difficulty.
Because this is a makeup exam, the highest you can earn on this exam is the equivalent of 75%. Your grade on the makeup exam will replace your grade on exam 1, provided your grade on the makeup exam is higher.
Please read the entire exam before you begin.
We expect that someone who has mastered the material and works at a moderate rate should have little trouble completing the exam in a reasonable amount of time. In particular, this exam is likely to take you about four hours, depending on how well you've learned the topics and how fast you work. You should not work more than five hours on this exam. Stop at five hours and write “There's more to life than CS” on the cover sheet of the examination and you will earn at least the equivalent of 70% on this exam, provided you recorded the time spent on each problem, filled in the prologue by the specified deadline, filled in the epilogue by the specified deadline, gotten at least two problems mostly right, and arranged for a meeting with me within one week of receiving your graded exam. You may count the time you spend on the prologue toward those five hours, but not the time you spend on the epilogue.. With such evidence of serious intent, your score will be the maximum of (1) your actual score or (2) the equivalent of 70%. The bonus points for recording time are not usually applied in the second situation, but penalties (e.g., for failing to number pages) usually are.
You should not count time reviewing readings, laboratories, or assignments toward the amount of time you spend on the exam or on individual problems.
We would also appreciate it if you would write down the amount of time each problem takes. Each person who does so will earn two points of extra credit for the exam. Because we worry about the amount of time our exams take, we will give two points of extra credit to the first two people who honestly report that they have completed the exam in four hours or less or have spent at least four hours on the exam. In the latter case, they should also report on what work they've completed in the four hours. After receiving such notices, we may change the exam.
This examination is open book, open notes, open mind, open computer, open Web. However, it is closed person. That means you should not talk to other people about the exam. Other than as restricted by that limitation, you should feel free to use all reasonable resources available to you.
As always, you are expected to turn in your own work. If you find ideas in a book or on the Web, be sure to cite them appropriately. If you use code that you wrote for a previous lab or homework, cite that lab or homework as well as any students who worked with you. If you use code that you found on the course Web site, be sure to cite that code. You need not cite the code provided in the body of the examination.
Although you may use the Web for this exam, you may not post your answers to this examination on the Web. And, in case it's not clear, you may not ask others (in person, via email, via IM, via IRC, by posting a please help message, or in any other way) to put answers on the Web.
Because different students may be taking the exam at different times, you are not permitted to discuss the exam with anyone until after we have returned it. If you must say something about the exam, you are allowed to say “This is among the hardest exams I have ever taken. If you don't start it early, you will have no chance of finishing.” You may also summarize these policies. You may not tell other students which problems you've finished. You may not tell other students how long you've spent on the exam.
You must include both of the following statements on the cover sheet of the examination.
Please hand write, sign, and date each statement separately. Note that the statements must be true; if you are unable to sign either statement, please talk to me at your earliest convenience. You need not reveal the particulars of the dishonesty, simply that it happened. Note also that “inappropriate assistance” is assistance from (or to) anyone other than Professor Rebelsky.
Exams can be stressful. Don't let the stress of the exam lead you to make decisions that you will later regret. Violations of academic honesty and exam policies will be handled through the Committee on Academic Standing, the College Hearing Board, or the Computer Science Department's Academic Honesty Policy, as appropriate.
You must present your exam in two forms, physically and electronically.
For the physical copy, you must write all of your answers using the computer, print them out, number the pages, staple them together (except for the cover sheet), and hand me the printed copy. For your benefit and for ours, we are doing blind grading on this examination, so you have been assigned a number to use on your exam. Please make sure that your number appears at the top of every page. You should turn in a separate cover sheet along with your stapled and printed answers. The cover sheet should include (1) the two hand-written academic honesty statements (individually signed and dated, if it is appropriate for you to sign each), (2) your name, and (3) your assigned number. If you choose to invoke the “there's more to life than computer science” option, then you must indicate that option on the cover sheet, and you should indicate it only on the cover sheet.
The code and comments in your printed copy must use a fixed-width (a.k.a., monospaced or fixed-pitch) font; depending on what platform you use, viable candidates include Monospace, Courier, Courier New, Monaco, DejaVu Sans Mono, Free Mono, Liberation Mono, and Lucida Sans Typewriter. Failure to format your code with a monospace font will result in a penalty. You may read the instructions on printing for more details on how to create readable output.
You must also submit the code for your examination at http://bit.ly/151-2015F-makeup1code. Please include the whole code file, including the supplied code that appears at the bottom of the template file.
In both cases (physical and electronic), you should put your answers in the same order as the problems. Failure to number the printed pages will lead to a penalty. Failure to turn in both versions may lead to a much worse penalty.
While your electronic version is due at 10:30 p.m. Tuesday, your physical copy will be submitted in class on Wednesday. It is presumed the physical copy matches the electronic copy. Any discrepancies (other than formatting) will likely be considered a misrepresentation of your work and referred appropriately.
In many problems, we ask you to write code. Unless we specify otherwise in a problem, you should write working code and include examples that show that you've tested the code informally (by looking at what value you get for various inputs) or formally (by using the Rackunit testing framework). In addition to the examples provided in the exam, you should also provide additional examples. Do not include resulting images; we should be able to regenerate those.
Unless we tell you otherwise, you should assume that you need to provide 6P-style documentation for each primary procedure you write. If you write any helper procedures, you must document them with 6P-style documentation using at least the first four P's (Procedure, Purpose, Parameters, Produces).
Just as you should be careful and precise when you write code and documentation, so should you be careful and precise when you write prose. Please check your spelling and grammar. We would appreciate it if you'd note any errors of spelling or grammar that I have, but we do not credit such errors in makeup examinations.
We will give partial credit for partially correct answers. We are best able to give such partial credit if you include a clear set of work that shows how you derived your answer. You ensure the best possible grade for yourself by clearly indicating what part of your answer is work and what part is your final answer.
I may not be available at the time you take the exam. If you feel that a question is badly worded or impossible to answer, note the problem you have observed and attempt to reword the question in such a way that it is answerable. If it's a reasonable hour (8am-10pm), feel free to try to call me (cell phone (text only) - 641-990-2947).
I will also reserve time at the start of classes the week the exam is due to discuss any general questions you have on the exam.
Since many students regularly seem to miss different elements of the exam, these checklists serve as a way to help you remember everything that you have to do.
000000 in the exam code with your random number?Topics: RGB Colors, color transformations, composition, documentation
Assume that
adds 32 to the red component of a color and
irgb-redder subtracts each
component of a color from 255. Carefully document the following
procedure using 6P-style documentation.
irgb-complement
(define irgb-crrc (o irgb-complement irgb-redder irgb-redder irgb-complement))
Topics: RGB colors, arithmetic, procedures
Write, but do not document, a procedure,
(, that takes one parameter, an
integer-encoded RGB color, and makes a new color in which any component
that is not equal to the largest component is set to 0.
irgb-clear-dominated
color)
For example,
>(irgb->string (irgb-clear-dominated (irgb 210 100 200)))"210/0/0">(irgb->string (irgb-clear-dominated (irgb 200 200 220)))"0/0/220">(irgb->string (irgb-clear-dominated (irgb 10 10 5)))"10/10/0">(irgb->string (irgb-clear-dominated (irgb 100 100 100)))"100/100/100"
irgb-addTopics: RGB colors, RGB transformations, testing
As you may recall, the procedure
takes as input two integer-encoded RGB colors and produces a new
integer-encoded RGB color whose components are the sum of the components
of the input colors. As is the standard for integer-encoded RGB colors,
if the sum of the components is greater than 255, we just use 255.
irgb-add
Write a test suite for .
Make sure to test some simple cases, some complex cases, and some
cases near the “boundaries” (which we tend to call
“edge cases” or “corner cases”). Here are
the beginnings of a test suite, with one test.
irgb-add
;;; Name:
;;; irgb-add-tests
;;; Type:
;;; test suite
;;; Contents:
;;; Tests for the irgb-add procedure.
(define irgb-add-tests
(test-suite
"Test of irgb-add"
(test-case "simple cases"
(check-equal? (irgb-add (irgb 128 0 0) (irgb 0 0 128))
(irgb 128 0 128)
"medium red plus medium blue = medium purple"))))
Topics: RGB Colors, arithmetic operations, color transformations
While the behavior of and
irgb-add is relatively sensible,
some people think that we should do something else when the sum of
the components is greater than 255 or the difference of the components
is less than 0. In particular, the normal suggestion is that we
“wrap around”, so that a sum of 255 goes to 0, a sum of
256 goes to 1, a sum of 257 goes to 2, and so on and so forth, and a
difference of -1 goes to 255, a difference of -2 goes to 254, and so
on and so forth.
irgb-subtract
Without using conditionals, write, but do not document, two
procedures ( and
component-add-wrap
component1
component2)( that exhibit this behavior.
component-sub-wrap
component1
component2)
;;; Procedure: ;;; component-add-wrap ;;; Parameters: ;;; component1, an integer ;;; component2, an integer ;;; Purpose: ;;; Add component1 and component2, "wrapping around" when the ;;; sum is greater than 255. ;;; Produces: ;;; wsum, an integer ;;; Preconditions: ;;; 0 <= component1 <= 255 ;;; 0 <= component2 <= 255 ;;; Postconditions: ;;; 0 < wsum <= 255. ;;; If component1 + component2 <= 255, ;;; wsum = component1 + component2 ;;; Otherwise, ;;; wsum = component1 + component2 - 256 ;;; Procedure: ;;; component-sub-wrap ;;; Parameters: ;;; component1, an integer ;;; component2, an integer ;;; Purpose: ;;; Subtract component2 and component1, "wrapping around" when the ;;; difference is less than 0. ;;; Produces: ;;; diff , an integer ;;; Preconditions: ;;; 0 <= component1 <= 255 ;;; 0 <= component2 <= 255 ;;; Postconditions: ;;; If component1 - component2 >= 0, ;;; diff = component1 - component2 ;;; Otherwise, ;;; diff = (component1 - component2) + 256
These procedures allow us to define variants of
and
irgb-add.
irgb-subtract
;;; Procedure:
;;; irgb-add-wrap
;;; Parameters:
;;; color1, an integer-encoded RGB color
;;; color2, an integer-encoded RGB color
;;; Purpose:
;;; Add color1 and color2 component-wise, wrapping around if any
;;; sum gets too large.
;;; Produces:
;;; color, an integer-encoded RGB color
;;; Preconditions:
;;; [No additional]
;;; Postconditions:
;;; If (irgb-red color1) + (irgb-red color2) <= 255,
;;; (irgb-red color) = (irgb-red color1) + (irgb-red color2)
;;; Otherwise,
;;; (irgb-red color) = (irgb-red color1) + (irgb-red color2) - 256
(define irgb-add-wrap
(lambda (color1 color2)
(irgb (component-add-wrap (irgb-red color1) (irgb-red color2))
(component-add-wrap (irgb-green color1) (irgb-green color2))
(component-add-wrap (irgb-blue color1) (irgb-blue color2)))))
;;; Procedure:
;;; irgb-sub-wrap
;;; Parameters:
;;; color1, an integer-encoded RGB color
;;; color2, an integer-encoded RGB color
;;; Purpose:
;;; Subtract color2 from color1 component-wise, wrapping around if any
;;; difference gets too large.
;;; Produces:
;;; color, an integer-encoded RGB color
;;; Preconditions:
;;; [No additional]
;;; Postconditions:
;;; If (irgb-red color1) - (irgb-red color2) >= 0,
;;; (irgb-red color) = (irgb-red color1) - (irgb-red color2)
;;; Otherwise,
;;; (irgb-red color) = ((irgb-red color1) - (irgb-red color2)) + 256
(define irgb-sub-wrap
(lambda (color1 color2)
(irgb (component-sub-wrap (irgb-red color1) (irgb-red color2))
(component-sub-wrap (irgb-green color1) (irgb-green color2))
(component-sub-wrap (irgb-blue color1) (irgb-blue color2)))))
Topics: Transforming RGB colors, composition, sectioning
Without using lambda, write a procedure,
that adds 64 to
each of the red and blue components and then averages the resulting
color with irgb-purple-grey(irgb 128 128 128).
You do not need to document
.
irgb-purple-grey
Topics: Transforming RGB colors, image variants, sectioning
The procedure averages
two colors, giving each equal weight. But what if we want to take
more of one color and less of another? We call such a combination
a “weighted average”.
irgb-average
Consider the following documentation of a new procedure,
.
irgb-weighted-average
;;; Procedure: ;;; irgb-weighted-average ;;; Parameters: ;;; color1, an integer-encoded RGB color ;;; color2, an integer-encoded RGB color ;;; weight, a real number ;;; Purpose: ;;; Compute a weighted average of two colors. ;;; Produces: ;;; new-color, an integer-encoded RGB color ;;; Preconditions: ;;; 0 *lt;= weight <= 1 ;;; Postconditions: ;;; Let r1, g1, and b1 be the components of color1. ;;; Let r2, g2, and b2 be the components of color2. ;;; Let r = weight*r1 + (1-weight)*r2 ;;; Let g = weight*g1 + (1-weight)*g2 ;;; Let b = weight*b1 + (1-weight)*b2 ;;; (floor r) <= (irgb-red new-color) <= (ceiling r) ;;; (floor g) <= (irgb-green new-color) <= (ceiling g) ;;; (floor b) <= (irgb-blue new-color) <= (ceiling b)
a. Implement .
(You don't need to document it because it's already documented.)
irgb-weighted-average
b. Implement, but do not document, a procedure,
( that takes an image and an
integer-encoded RGB color as inputs and does a weighted average of each
pixel in image-tint image
color)image with color,
weighting the original color in the image by 90% and the new color
by 10%. If you did not succeed in writing
, you may use
irgb-weighted-average to average each pixel
with irgb-averagecolor
Topics: Numeric values, code reading, documentation
Consider the following procedure.
(define f (lambda (a b c) (min (max (min a b) c) (max (min b c) a))))
Reformat the procedure (i.e., by adding new lines) so that its
operations are easier to understand. Next, try calling it with a
wide variety of parameters. Your goal is to discover what parameters
f accepts and what it does with those parameters.
Then rewrite the procedure definition as follows:
Here we will post answers to questions of general interest. Please check here before emailing your questions!
STUB comment that appears in the code
file?
Here you will find errors of spelling, grammar, and design that students have noted. For makeup exams, I don't give credit for such corrections, but I do list them here (anonymously).
Some of the problems on this exam are based on (and at times copied from) problems on previous exams for the course. Those exams were written by Janet Davis, Rhys Price Jones, Samuel A. Rebelsky, John David Stone, Henry Walker, and Jerod Weinman. Many were written collaboratively, or were themselves based upon prior examinations, so precise credit is difficult, if not impossible.
Some problems on this exam were inspired by conversations with our students and by correct and incorrect student solutions on a variety of problems. We thank our students for that inspiration. Usually, a combination of questions or discussions inspired a problem, so it is difficult and inappropriate to credit individual students.