Functional Problem Solving (CSC 151 2016S) : EBoards

CSC151.02 2016S, Class 13: Testing Your Procedures, Revisited


Overview

Preliminaries

Admin

Reminders

Upcoming Work:

Extra Credit

Academic

Peer

Regular Peer

No Extra Credit, But Still Good

Quiz 3

(define f (section + <> 1)) ; add a value and 1
(define g (section - 2 <>)) ; 2 minus input number; subtract from 2
(define h (section remainder <> 4)) ; divides input by 4 and takes remainder

; Show your steps
> (h (h 15))
; (h 15) is (remainder 15 4) is 3
; (h 3) is (remainder 3 4)

;;; Procedure:
;;;   irgb-only-green
;;; Parameters:
;;;   color, an integer-encoded RGB color
;;; Purpose:
;;;   Computes a new color with the same green component and
;;;   0's for the other components.
;;; Produces:
;;;   only-green, an integer-encoded RGB color
;;; Preconditions:
;;;   [No additional]
;;; Postconditions:
;;;   (irgb-green only-green) = (irgb-green color)
;;;   (irgb-red only-green) = 0
;;;   (irgb-blue only-green) = 0
(define irgb-only-green
  (lambda (color)
    (irgb 0
          (irgb-green color)
          0)))

I did not want

(define irgb-only-green
  (lambda (color)
    (irgb (* 0 (irgb-red color))
          (irgb-green color)
          (* 0 (irgb-blue color)))))

(define irgb-only-green
  (lambda (color)
    (irgb (- (irgb-red color) 255)
          (irgb-green color)
          (- (irgb-blue color) 255))))

(define irgb-only-green
  (lambda (color)
    (irgb (min 0 (irgb-red color))
          (irgb-green color)
          (min 0 (irgb-blue color)))))

(define irgb-only-green
  (lambda (color)
    (irgb (- (irgb-red color) (irgb-red color))
          (irgb-green color)
          (- (irgb-blue color) (irgb-blue color)))))

These alternate solutions have more text and may be harder to read/understand.

They are also inefficient, they require the computer to do unnecessary work.

(hsv->irgb (hsv (+ 360 (irgb->hue color))
                (irgb->saturation color)
                (irgb->value color)))

is a really long way to say color.

Help on Exam 1

Problem 2

You may find that this approximates the result, and you can say so.

Problem 3

On HW 3, you probably wrote an expression that gave you 0 if the red component was the smallest and 1 if the red component was not the smallest. You can use a similar idea here.

Problem 4a

We've done a lot of bounding. Look back at it. (E.g., look at problem 1 on the procedures lab.)

Problem 4b

You can use 191 instead of 192 as the upper bound.

You probably need a different technique for 4b than you used for 4a.

The key transforms: irgb-add, irgb-subtract, irgb-average, irgb-darker, irgb-lighter, irgb-redder, irgb-greener, irgb-bluer, and irgb-complement.

We've seen some instances in which we combine color transforms and suddenly find that some values are no longer available. For example, are there a sequence of transforms that ensure that any component below 16 becomes 16?

Problem 5

You should have seen a similar problem on a homework.

And I probably gave you too much of a hint above in telling you what not to do.

Your examples should be things like

; > (image-show (color-palette (color-name->irgb "steelblue"))) ; > 3 ; ; Yup, looks right!

You do not have to cite the "Yup, looks right!"

Problem 6

The names are awful. Think about the context in which they are used.

Questions

How do we turn in the exam?

Save the racket file as 000000.rkt

Email it to Sam as an attachment with a title of "CSC 151 Exam 1 (Your Name)"

Take a blank sheet of paper. Write your name, your number, and the academic honesty statements. Sign and date whichever academic honesty statements you feel comfortable signing. (And the There's More To Life Clause, if appropriate)

Do we need to cite these hints or code from the exam?

No!

Do we need to cite last Thursday's mentor session when Alex gave away inappropriate hints on the exam?

Yes!

Will DrRacket crash and completely destroy the exam of at least one student in this class?

Yes. I recommend that you mail yourself a copy regularly.

If we are typing English and we go beyond 70 or so columns, should we hit the Return key and another semicolon?

Yes.

What's a Carriage Return?

Go on to the next line.

What is #

Octothorpe

What's your philosophy on carriage returns?

They should clarify nesting.

Not

    (+ 23
       (* 24 12) 12)

How long will it take you to fix all the problems?

Heat death of the universe.

If you notice that I've fixed something and you relied on a previous definition, just note so in your exam.

Pair programming

What are three key points from the reading?

Lab

Don't worry about it!