Lecture: 10-22-2012

posted Oct 22, 2012, 6:24 AM by Samuel Konstantinovich   [ updated Nov 20, 2012, 5:41 AM ]
;10/22/2012
;GOAL: Practice with list processing

;DO NOW: Trace through the two mystery functions:
(define (mist X)
  (cond
    ((null? X) '())
    ((= 0 (car X) ) (caddr X))
    (else  (mist (append (cdr X) (list (car X)))))))

;Trace this code:
(mist '(18 31 22 0 75))

(define (fist n)
  (cond
    ((= n 0) '())
    (else (cons n (fist (- n 1)))))) 
    
;trace this code:
(fist 5)
 
;Discussion on: LIST BOX DIAGRAMS 
;'(1 3 5 9)
;'(1 ( 2 3) 4)
;'(8 ( 2 3 4) 9 (10 3 0))

;Practice Problems:
;0. Write a function that adds up all of the integers in
;a list of real numbers.  (sumInt '(1  2  3.5  5.2))  is 3

;1. Write a function that calculates how many odd values 
;are in a list of integers (countOdd '(1 2 3 4 10 13) ) is 3

;2. Write a function that creates a list of the first n
;perfect squares  (create 4)  ->  ( 1 4 9 16)  OR  (16 9 4 1)
;can you make it in the opposite order you already made it?

;3. Write a function that takes a list, and returns the
;list with the values doubled:  (double '(3 4 9)) -> (6 8 18)

Comments