CSE341 Key to Final, Autumn 2007 handout #23 1. Scheme expressions. Part A: (define a 2) (define b 4) (define c 8) (let ((a (+ a c)) (b (+ a b))) (list a b c)) (10 6 8) Part B: (define a 4) (define b 8) (define c 12) (let* ((a (+ a c)) (c (+ a b))) (list a b c)) (16 8 24) Part C: (define a '(b)) (define b (cons a '(b c))) (set-car! a 12) (set! a 5) (set-car! (cdr b) a) (list a b) (5 ((12) 5 c)) Part D: (define a '(1 2)) (define b (cons 8 a)) (define c (append b a)) (set-car! (cdr b) 16) (set-car! b 24) (list a b c) ((16 2) (24 16 2) (8 1 2 16 2)) 2. One possible solution appears below. (define (cube-sum n) (cond (( y.length max = x.length else max = y.length end max.times do |i| n = 0 n += x[i] if x[i] n += y[i] if y[i] result.push n end result end 11. One possible solution appears below. class Array def running_sum sum = 0 for n in self sum += n yield sum end sum end end 12. One possible solution appears below. class Array def collapse result = [] i = 0 while i Source.


Яндекс.Метрика Рейтинг@Mail.ru Free Web Counter
page counter
Last Modified: April 23, 2016 @ 9:04 am