;; Homework #4 ;; D.S. Blank ;; 1. Write 'interleave' that takes two lists, and weaves them ;; together. (interleave '(1 2 3) '(a b c)) ;; (1 a 2 b 3 c) (interleave '(1 2 3) '(a b c d e f)) ;; (1 a 2 b 3 c d e f) (interleave '() '(a b c d e f)) ;; (a b c d e f) (interleave '(1 2 3 4 5 6 7 8 9 10) '(a b c d e f)) ;; (1 a 2 b 3 c 4 d 5 e 6 f 7 8 9 10) ;; 2. Write 'sum' that computes the sum of a list of numbers. (sum '()) (sum '(0)) (sum '(1 2 3 4)) (sum '(100 200 300)) ;; 3. Write 'naturals' that returns a list of the n first natural ;; numbers. (naturals 0) (naturals 10) ;; Try (sum (naturals 10)) (sum (naturals 10)) ;; 4. Write 'fibonacci' to return the nth fibonacci number. (fibonacci 0) (fibonacci 1) (fibonacci 10) ;; How high can you go? ;; 5. To test fibonacci, write 'progression' that takes a function and ;; the number of times to apply it. (progression fibonacci 10) ;; > (progression fibonacci 10) ;; (89 55 34 21 13 8 5 3 2 1 1) ;; 6. Write naturals2 using progression. It should still take a number ;; n. (naturals2 10) ;; > (naturals 10) ;; (10 9 8 7 6 5 4 3 2 1 0) ;; 7. Write 'member?' that returns #t if atom is in list, otherwise ;; returns #f. (member? 'a '(a b c)) ;; #t (member? 'a '()) ;; #f ;; 8. Write 'rember' that removes the first occurance of and atom from ;; a list. (rember 'a '(a a a)) ;; (a a) (rember 'a '(1 2 3)) ;; (1 2 3) (rember 'a '(b c a)) ;; (b c) ;; 9. Write 'rember*' that removes all of the occurances of an atom in ;; a list. (rember* 'a '(a a a a)) ;; () (rember* 'b '(a a a a)) ;; (a a a a) (rember* 'a '(a (a) b c (a))) ;; (() b c ()) ;; 10. Write 'scheme-exp' that returns a scheme expression for getting ;; an atom out of a list. You'll probably need at least two functions. (scheme-exp 'a '(c b a)) ;; (car (cdr (cdr '(c b a)))) ;; (scheme-exp 'a '(c b d)) ;; error! (scheme-exp 'c '(c b a)) ;; (car (c b a)) ;; 11. Write 'depth' to find the deepest part of a tree. If you can, ;; don't compute the depth of any part more than once. (depth '(1 2 3)) ;; 0 (depth '(1 (2 5) (((3))))) ;; 3