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: Wednesday, 16 September 2015
Due: The due dates for various tasks are as follows.
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.
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 errors and 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 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-exam1. Ideally, you would put all of the code
for the exam in a single Racket file. However, if you have created
separate files for the separate parts of the exam, you can just
paste them one after another when you submit, provided you put a
clear separator, such as ; PROBLEM 2, between sections.
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. Because we should be equally careful, the whole class will receive one point of extra credit for each error in spelling or grammar you identify in the preliminaries and problems on this exam. We will limit that form of extra credit to five points.
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.
Topics: Numeric values, writing procedures, section, composition
Without using lambda or if, write, but do
not document, a procedure, ,
that takes one input, a real number that we'll call
bound-rating, and returns
rating
rating < 0
rating > 10
rating, if neither of the two previous conditions
holds.
Note that to define this procedure, you will find it necessary to
use ,
o or both. You will also
find it useful to go back and think about how we've bounded values
in past exercises.
section
Topics: Procedures, numeric computation
Write, but do not document, a procedure,
(
that returns
index-of-largest val1
val2 val3)
1, if val1 is
larger than the other two values,
2, if val2 is
larger than the other two values,
3, if val3 is
larger than the other two values, and
>(index-of-largest 100 50 0)1>(index-of-largest 100 0 50)1>(index-of-largest 50 100 0)2>(index-of-largest 0 100 50)2>(index-of-largest 0 50 100)3>(index-of-largest 50 0 100)3
You may not use conditionals (e.g., if) in writing
.
index-of-largest
Topics: Code reading, times, complex numbers, numeric computation, abusing Scheme
Suppose we want to do math with times, and we limit ourselves to times that involve minutes and seconds. How do we represent both minutes and seconds? Here's a not-necessarily-clever trick: We could use complex numbers. The real part of the imaginary number represents the minutes and the imaginary part represents the seconds.
Here are some procedures that allow us to work with that representation.
;;; Procedure:
;;; time
;;; Parameters:
;;; min, a non-negative integer
;;; sec, a non-negative integer
;;; Purpose:
;;; Generate a representation of min minutes and sec seconds
;;; Produces:
;;; tm, a complex number representing a time
;;; Preconditions:
;;; [No additional]
;;; Postconditions:
;;; (minutes tm) = min
;;; (seconds tm) = sec
(define time
(lambda (min sec)
(+ min (* 0+i sec))))
;;; Procedure:
;;; minutes
;;; Parameters:
;;; tm, a complex number representing a time
;;; Purpose:
;;; Extract the minutes from tm
;;; Produces:
;;; min, an integer
(define minutes real-part)
;;; Procedure:
;;; seconds
;;; Parameters:
;;; tm, a complex number representing a time
;;; Purpose:
;;; Extract the seconds from tm
;;; Produces:
;;; sec, an integer
(define seconds imag-part)
;;; Procedure:
;;; display-time
;;; Parameters:
;;; tm, a complex number representing a time
;;; Purpose:
;;; Display the time.
;;; Produces:
;;; [Nothing; called for the side effect]
(define display-time
(lambda (tm)
(display (minutes tm))
(display " minutes and ")
(display (seconds tm))
(display " seconds.")
(newline)))
Write, but do not document, a procedure,
( that adds the two times
appropriately. For example,
add-times time1
time2)
>(define t1 (time 5 35))>(minutes t1)5>(seconds t1)35>(display-time t1)5 minutes and 35 seconds.>(define t2 (add-times t1 t1))>(minutes t2)11>(display-time t2)11 minutes and 10 seconds.>(display-time (add-times t1 t2))16 minutes and 45 seconds.
Your procedure should correctly limit the number of seconds to between 0 and 59, even if the input time is not in that form.
>(define t3 (time 0 97))>(display-time t3)0 minutes and 97 seconds.>(define t4 (add-times t3 t3))>(display-time t4)3 minutes and 14 seconds.>(display-time (add-times (time 0 0) t3))1 minutes and 37 seconds
Write a test suite for .
add-times
We will likely run your test suite on a variety of
implementations of ,
including some that are mostly, but not completely, correct.
add-times
Note: Your tests should only involve correct calls
to . If, for
example, the times are negative, there are no
restrictions on what the procedure should do.
add-times
Topics: Numeric functions, reading code, procedures, documentation
Consider the following procedure.
(define fun
(lambda (n i)
(quotient (remainder n (expt 10 (+ i 1))) (expt 10 i))))
Your job is to be a code detective. Read the procedure definition carefully and call the procedure with many different parameters to learn what the procedure does and how it works.
Hint: Try using large values of
n and small values of i.
You can discover the purpose of the procedure either by trying many
examples or by working through an example by hand.
a. In your own words, describe what
fun computes. That is, explain the purpose of the
procedure.
b. In your own words, explain how
fun works. That is, explain the algorithm that is
used.
c. What limitations are there on n and
i in order for this procedure to work
sensibly?
Topics: Integer-encoded RGB colors, code reading, documentation
Consider the following definitions.
;;; Procedure:
;;; irgb-component-add
;;; Parameters:
;;; color, an integer-encoded RGB color
;; offset, an integer
;;; Purpose:
;;; Add offset to each of the components of color.
;;; Produces:
;;; new-color, an integer-encoded RGB color
;;; Preconditions:
;;; offset >= 0
;;; Postconditions:
;;; (irgb-red new-color) = (min 255 (+ offset (irgb-red color)))
;;; (irgb-green new-color) = (min 255 (+ offset (irgb-green color)))
;;; (irgb-blue new-color) = (min 255 (+ offset (irgb-blue color)))
(define irgb-component-add
(lambda (color offset)
(irgb (+ offset (irgb-red color))
(+ offset (irgb-green color))
(+ offset (irgb-blue color)))))
;;; Procedure:
;;; irgb-component-sub
;;; Parameters:
;;; color, an integer-encoded RGB color
;; offset, an integer
;;; Purpose:
;;; Subtract offset from each of the components of color.
;;; Produces:
;;; new-color, an integer-encoded RGB color
;;; Preconditions:
;;; offset >= 0
;;; Postconditions:
;;; (irgb-red new-color) = (max 0 (- (irgb-red color) offset))
;;; (irgb-green new-color) = (max 0 (- (irgb-green color) offset))
;;; (irgb-blue new-color) = (max 0 (- irgb-blue color) offset))
(define irgb-component-sub
(lambda (color offset)
(irgb (- (irgb-red color) offset)
(- (irgb-green color) offset)
(- (irgb-blue color) offset))))
(define irgb-strange
(lambda (x y)
(irgb-component-add (irgb-component-sub x y) y)))
Write the six-P style documentation for
. You may find
it useful to rename the parameters.
irgb-strange
Topics: Integer-encoded RGB colors, color transformations, image transformations, procedures, bounded values, sectioning.
Consider the following procedure documentation.
;;; Procedure: ;;; irgb-bound-components ;;; Parameters: ;;; color, an integer-encoded RGB color ;;; lower, an integer ;;; upper, an integer ;;; Purpose: ;;; Bound the components to be in the range [lower .. upper] ;;; Produces: ;;; bound, an integer-encoded RGB color ;;; Preconditions: ;;; 0 <= lower <= upper <= 255 ;;; Postconditions: ;;; If (irgb-red color) < lower, then (irgb-red bound) = lower ;;; If (irgb-red color) > upper, then (irgb-red bound) = upper ;;; If neither of the preceding two cases holds, then ;;; (irgb-red bound) = (irgb-red color) ;;; If (irgb-green color) < lower, then (irgb-green bound) = lower ;;; If (irgb-green color) > upper, then (irgb-green bound) = upper ;;; If neither of the preceding two cases holds, then ;;; (irgb-green bound) = (irgb-green color) ;;; If (irgb-blue color) < lower, then (irgb-blue bound) = lower ;;; If (irgb-blue color) > upper, then (irgb-blue bound) = upper ;;; If neither of the preceding two cases holds, then ;;; (irgb-blue bound) = (irgb-blue color)
a. Implement the
procedure. (We've already provided the documentation.)
irgb-bound-components
b. Using your implementation, write, but do not document, a procedure
(
that creates a variant of image-mid image)
in which every color component is bounded below by 64 and above by 196.
image
Here we will post answers to questions of general interest. Please check here before emailing your questions!
; --------- PROBLEM 2 -------------.
<> in
section? [2015-09-18]
<> refers to a separate
input. However, it's unlikely to be helpful for this problem,
since you only have one input. You will certainly find
section useful. You will
also find composition useful.
(check-equal? (minutes (add-times (time 1 40) (time 2 40))) 4);;; Name: ;;; ... ;;; Type: ;;; test suite ;;; Value: ;;; ...
Here you will find errors of spelling, grammar, and design that students have noted. Remember, each error found corresponds to a point of extra credit for everyone. We usually limit such extra credit to five points. However, if we make an astoundingly large number of errors, then we will provide more extra credit. (And no, we don't count errors in the errata section or the question and answer sections.)
irgb-component-sub. [GN, BD, and SJ, 1 point].
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.