Assignment 1: Finger Exercises

###
Assignment 1: Finger Exercises

Before you tackle the homework, remind yourself of our General Advice, Advice on Homeworks, and Grading Guidelines. Above all, keep your work neat and honest.

1. (3pts) Evaluate each of the following expressions. Show every step. For example:

         (sqrt (+ (* 3 3) (* 4 4)))
       = (sqrt (+ 9 (* 4 4)))
       = (sqrt (+ 9 16))
       = (sqrt 25)
       = 5

   The red part is called the reducible expression. You may wish to underline those in your homework by hand.

   1. `(- (* 3 5) 20)`
   2. `(/ 44 (+ 8 3))`
   3. `(+ #f 10)`
   4. `(log (exp 1.0))`
   5. `(zero? (+ 2 -2))`
   6. `(and (= 3 3) (or (zero? 17) (> 17 0)))`

   7.     (cond
            ((zero? (sqrt 16)) #f)
            (else (+ 3 10)))

   8.     (cond
            ((and (zero? 0) (> 17 0))
             #f)
            (else
              (+ (sin 0)
                 (* (cos 1.3) (cos 1.3)))))

   9.     (cond
            ((sqrt 16) #f)
            (else (+ 3 10)))

   10. Given

           ;; experiment : number -> number
           (define (experiment t)
             (cond
               [(< t 0) 0]
               [(> (distance t) 200) 200]
               [else (distance t)]))

           ;; distance : number -> number
           (define (distance t)
             (* 1/2 t t G))

           ;; G : gravitational acceleration
           (define G 9.81)

       what are the results of

           (experiment 5)
           (experiment -1)
           (experiment 20)

   Type the steps into the Definition window and check them. You may wish to use several files and print them separately.
2. (4pts) At least one of the department's professors drivers loves to accelerate quickly. He accelerates quickly when the light turns from red to green to the de-facto speed limit of 80 miles per hour (mph) and then maintains that constant speed. Write a Scheme program that takes two inputs:
   1. the acceleration (in mph per second) of a car, and
   2. an elapsed driving time in seconds
   and returns the distance traveled (in miles).

   Your physics consultant advises: Newton figured out that if an object accelerates at a (meter/second) per second [that is, "(miles per second) per second" for Libyans and Americans], it travels

   `.5 * a * t * t`

   meters [miles] in t seconds and reaches a speed of

   `a * t`

   meters per second [miles per second] in the same time span.

   Hint: Use several helper functions to make your program more readable.

3. (3pts) Either Exercise 6.3.2 or 6.3.3.
4. (Extra credit: 3pts) Exercise 6.3.4. Extend only the exercise you chose in item 3.

Matthias Felleisen | This page was generated on Fri Mar 5 09:05:54 CST 1999.