Re-read the adages page, the material on Pair Programming, and perhaps this article on computational thinking for non-computer-scientists. Choose one (or several closely-related) adages, or one longer article, that mean more to you than they did at the beginning of the term.
Write an essay of one to five well-structured paragraphs on what this adage really means in practice. Do you agree or disagree? Support your claims with specific examples from your experience this semester.
You may also want to comment on your experience of Pair Programming: how well did it work, what were the advantages and disadvantages, what would make it work better, etc.?
Do not turn these in: I won't have time to grade them anyway. However, they're good exercises to do, and will help you prepare for the final exam.
Develop a function named add-up-to
which takes in a natural number and returns the sum of all the natural
numbers up to and including it.
Example:
(check-expect (add-up-to 3) 6) (check-expect (add-up-to 5) 15) (check-expect (add-up-to 10) 55)Note: there is a formula for this, but I want you to do it recursively, using only addition (no multiplication or division).
Develop a function named
dot-grid
that takes two natural numbers width
and height
, and produces a rectangular grid of circles with
width
columns and height
rows.
Example:
Develop a function randoms
that takes two natural numbers how-many
and limit
and
produces a list of how-many
numbers, each chosen randomly
from 0 up to limit
.
Example:
(randoms 10 15) (list 11 7 5 3 14 2 14 5 13 10)
Note: as usual with random functions, you won't be able to specify exactly what the right answer should be, so just describe the answer (e.g. "should be a list of 7 numbers ranging between 0 and 5 inclusive")
Develop a function table-of-squares
which takes in a natural number and returns a list of
posn
s representing a table of numbers and
their squares up to the given number.
Example:
(check-expect (table-of-squares 4) (list (make-posn 4 16) (make-posn 3 9) (make-posn 2 4) (make-posn 1 1) (make-posn 0 0))Note: I've put these in descending order because it's easier to write the function that way. It's a good additional exercise to produce the table in increasing order instead.
For these problems, you'll need to be in DrScheme's Intermediate language.
Develop a function remove-if
which takes in a list of X's (for any data type X), and a
function from X to boolean, and returns a list of X's containing only
the ones for which the function is false.
Develop a function
fire-over-100K
that takes in a list of employees (see
worked exercises
16.2.1 and 16.4.1)
and returns a list of the employees who earn under $100,000.
Hint: you should be able to do this in one or two
lines by re-using previously-defined functions.
Develop a function
give-10%-raises
that takes in a list of employees and
returns a list of the same employees, each earning 10% more than
before.
Hint: Use do-to-each
on a
function that operates on a single employee.
Modify the animation from homework 9 to use do-to-each
wherever
possible. The result should be much shorter and simpler than what you
did for homework 9.
Develop a function do-twice
that
takes in a function with contract "X -> X", and returns a
function with the same contract which applies the given function
twice. For example,
(define add2 (do-twice add1)) (check-expect (add2 3) 5)What does
(do-twice sqr)
do?
Generalize this to a function iterate
that takes a natural number and a function with contract "X -> X",
and returns a function with the same contract which applies
the given function the specified number of times. For example,
(iterate 2 f)
should be equivalent to (do-twice f)
, and
(define add5 (iterate 5 add1)) (check-expect (add5 3) 8)What does
(iterate 3 sqr)
do?
What about (iterate 5 sqr)
?
(iterate 3 (iterate 3 sqr))
?
(iterate 3 do-twice)
?
For these problems, you'll need to be in DrScheme's Advanced language.
Develop a function named next
that
takes no arguments, but each time you call it, it returns how many
times it has been called. Example:
> (next) 1 > (next) 2 > (next) 3
Develop a function named next-color
that takes no arguments, but each time you call it, it returns the next
element in the list (list "red" "orange" "yellow" "green" "blue"
"violet")
. If you call it more than six times, it returns
false
.
Example:
> (next-color) "red" > (next-color) "orange" > (next-color) "yellow" > (next-color) "green" > (next-color) "blue" > (next-color) "violet" > (next-color) false
The essay should be written individually and turned in with one name at the top. The programming problems should not be turned in. You are free to work with anybody you wish in solving them. Call it a study group.