CS 2010 Homework 4   - Due September 16

Setup

hw1-extras.plt
Download and install hw1-extras.plt from HW 1, but only if you haven't already. For HW 4, you do not need hw1-teachpack.ss.
hw2-extras.plt
Download and install hw1-extras.plt from HW 2, but only if you haven't already. For HW 4, you do not need hw2-teachpack.ss.
hw4-extras.plt
Install these extra primitive operations to be used in the assignment. To install, download hw4-extras.plt, open hw4-extras.plt using DrScheme's Open menu item, and allow DrScheme to install the package.
hw4-teachpack.ss (and clear any other teachpack)
Download and select this teachpack for the assignment. To select the teachpack, first use the Clear Teachpacks menu item to clear old teachpacks. Then use the Add Teachpack... menu item in the Language menu. (Do not use DrScheme's Open menu item for hw4-teachpack.ss.)

The teachpack adds the following primitive operations, in addition to those of HW 1:

(define-struct color (red green blue))
Colors on a computer screen are represented by a combination of red, green, and blue light intensities. The intensity of each color varies between 0 and 255. For example, pure blue is (make-color 0 0 255), while (make-color 0 0 128) is a dim blue. Using the same intensity for red, blue, and green always produces a shade of gray; in particular, (make-color 0 0 0) is black, (make-color 255 255 255) is white, and (make-color 128 128 128) is a medium gray. Other combinations produce other colors. For example, (make-color 255 255 0) is bright yellow.
image->color-list : image -> list-of-color
Returns a list of color values representing the pixels of a given image. The first color corresponds to the top-left pixel, the second color corresponds to the pixel one step to the right, and so on --- left-to-right then top-to-bottom. The number of colors is in the list is the same as the image's width times its height.
color-list->image : list-of-color num num -> image
The opposite of image->color-list. This function needs the width and height of the image to construct, in addition to the pixel content.

Assignment

Exercise 4.1, Product

Define the function product, which takes a list of numbers and produces the result of multiplying all of the numbers together. The product of an empty list is 1, for the same reason that n0 is 1 for any n.

Use the standard definition of list of numbers:

; A list-of-num is either
;  - empty
;  - (cons num list-of-num)

Exercise 4.2, Inflation

Define the function inflate-by-4%, which takes a list of numbers representing prices and returns a list of the prices inflated by 4%.

Define the function inflate-by-rate, which takes a list of numbers representing prices and an inflation rate (eg. 0.04 for 4% inflation). The function should returns a list of the prices inflated by the given rate.

Exercise 4.3, An Apple A Day

Define the function eat-apples, which takes a list of symbols and returns a list containing the example symbols, except that every instance of 'apple is removed. For example, if a list of 10 symbols is provided where 'apple appears twice, the result is a list of 8 symbols.

Exercise 4.4, Distances

Define the function distances, which takes a list of posns and returns a list of numbers that represent the distance from each posn to the origin. (See also section 6.1 in the textbook, page 54.)

Exercise 4.5, Photo Negative

Define the function photo-negative, which takes an image and returns a "negative" of the image. To create a negative, flip each of the red, green, and blue intensities of the image's pixels. For example, pure blue (make-color 0 0 255) turns into pure yellow (make-color 255 255 0), while medium gray (make-color 128 128 128) changes imperceptibly to (make-color 127 127 127).

Hint: most of the work should be in a helper function that is possibly named negate-colors.

Exercise 4.6, Kind of Blue

Define the function kind-of-blue?, which takes an image and returns true if the total blue intensity of pixels in the image is greater than the total red intensity, and also greater than the total green intensity.

Hint: write three helper functions to compute three different total intensities.

For example, is not blue, but is kind-of blue.

Exercise 4.7, Image Comparisons

Define the function same-image?, which takes two images and determines whether they are exactly the same. Do not use image=?.


Last update: Tuesday, September 16th, 2003
mflatt@cs.utah.edu