Functional Problem Solving (CSC 151 2016S) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Taking Notes] [Rubric]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Labs] [Outlines] [Readings] - [Examples] [Handouts]
Reference: [Setup] [Remote] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Curtsinger (2016S)] [Davis (2013F)] [Rebelsky (2015F)] [Weinman (2014F)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)]
Overview
Topics
max, min,
floor, ceiling, round, quotient, and remainder.
remainder
and modulo.irgb-redder, irgb-greener, irgb-bluer, irgb-darker,
irgb-lighter, irgb-complement, irgb-rotate, irgb->string(compose irgb-redder irgb-darker).image-load, image-save, image-variantForm
I can't do math in my head. Are calculators okay?
Probably not; I don't think we have anything particularly complicated on the quiz. Mostly addition and subtraction. Plus, you have paper!
Do we have to memorize how much each transform changes things?
No. We'll tell you. We may be cruel enough that we will give you different definitions (e.g., "assume
irgb-redderadds 11 to the red component, bounding at 255 ...")
Do we have to be able to convert RGB triples to those unreadable numbers?
NO!
What transformations can't be undone? It seems like most of the time we are adding and subtracting, so you just do the inverse.
You can't do the inverse when we "cap" the value. E.g.,
(irgb-lighter (irgb-darker (irgb 0 10 15)))gives us(irgb 16 16 16), which is not the same. If the result of(irgb-darker x)is black, we can't tell which of the 8000 or so fairly dark colorsxwas.Similar issues for
irgb-redder,irgb-bluer,irgb-greener,irgb-lighter.
Is there a way to add 3 to the red component, assuming color is already
an integer-encoded IRGB color?
(irgb-add color (irgb 3 0 0))
Do we get extra credit for catching typos in your quizzes?
Not usually. Sometimes typos affect solvability, in which case yes.
Given that
irgb-redder adds 32 to the red component (bounding at 255)irgb-greener adds 32 to the green component (bounding at 255)irgb-bluer adds 32 to the blue component (bounding at 255)irgb-complement subtracts each component from 255irgb-darker subtracts 16 from each component (bounding at 0)irgb-lighter adds 16 to each component (bounding at 255)(irgb->string (irgb-darker (irgb-lighter (irgb 16 192 240))))
(irgb->string (irgb-lighter (irgb-darker (irgb 16 192 240))))
(irgb-lighter (irgb 16 192 240)) -> (irgb 32 208 255)
(irgb-darker (irgb 32 208 255)) -> (irgb 16 192 239)
"16/192/239"
(irgb-darker (irgb 16 192 240)) -> (irgb 0 176 224)
(irgb-lighter (irgb 0 176 224)) -> (irgb 16 192 240)
"16/192/240"
(floor (+ 1/2 (ceiling (- 1/2 (round 2.5)))))
(ceiling (+ 1/2 (truncate (- 1/2 (floor 2.5)))))
(round 2.5) -> 2
(- 1/2 2) -> -3/2
(ceiling -3/2) -> -1
(+ 1/2 -1) -> -1/2
(floor -1/2) = -1
(floor 2.5) -> 2
(- 1/2 2) -> -3/2
(truncate -3/2) -> -1
(+ 1/2 -1) -> -1/2
(ceiling -1/2) -> 0
Without using section, lambda, or irgb-darker, write a procedure,
irgb-much-darker, that takes an integer-encoded RGB color as input
and subtracts 32 from each component (bounding at 0).
(define irgb-much-darker (irgb-complement irgb-lighter irgb-lighter irgb-complement))
For a component, c
255 - (16 + (16 + (255 - c)))
255 - (16 + 16 + 255 - c)
255 - (16 + 16 + 255) + c
255 - 32 - 255 + c
-32 + c
If we were allowed to use section
(define irgb-much-darker (section irgb-subtract <> (irgb 32 32 32)))
Without using section, or lambda write a procedure, irgb-less-blue,
that takes an integer-encoded RGB color as input and subtracts 32 from
the blue component (bounding at 0).
Without using section or lambda, write a procedure, quad, that
takes a number is input and computes the number to the fourth power.
(define quad (compose square square))
Consider this definition
(define fun (compose irgb-darker irgb-redder irgb-greener))
What is
(irgb->string (fun (irgb 16 192 210)))
Explain concisely what fun computes.
Consider this definition
(define fun (compose irgb-complement irgb-darker irgb-bluer irgb-greener irgb-complement))
What is
(irgb->string (fun (irgb 16 192 210)))
Explain concisely what fun computes.
funsubtracts 16 from the green and blue components and adds 16 to the red component.No, I probably wouldn't ask something quite that complex on a quiz, but maybe on an exam.
Assume that (square x) computes (* x x). Consider this definition
(define fun (compose floor square))
What is
(fun 3.9)
Explain what the result of the following expression is in terms of x.
(- x (remainder x 5))
The difference between x and the remainder of x/5. (No; just a translation into English.)
The nearest multiple of 5 to x.
What values can the following expression take on?
(- (floor x) (round x))
What does truncate do?
Cuts off everything after the whole part.
Rounds down for positive, rounds up for negative.
What does "explain concisely" mean?
Talk about the apparent purpose, rather than the steps involved.
Give a "high level" overview.