Computer Science 21b: Structure and Interpretation of ...mairson/Courses/cs21b/Lectures/Midt… ·...

9
Computer Science 21b: Structure and Interpretation of Computer Programs Autumn Term, 2010 Midterm exam results

Transcript of Computer Science 21b: Structure and Interpretation of ...mairson/Courses/cs21b/Lectures/Midt… ·...

Page 1: Computer Science 21b: Structure and Interpretation of ...mairson/Courses/cs21b/Lectures/Midt… · Computer Science 21b: Structure and Interpretation of Computer Programs Autumn Term,

Computer Science 21b:Structure and Interpretation of Computer ProgramsAutumn Term, 2010Midterm exam results

Page 2: Computer Science 21b: Structure and Interpretation of ...mairson/Courses/cs21b/Lectures/Midt… · Computer Science 21b: Structure and Interpretation of Computer Programs Autumn Term,

(define (anonymous student) (cons '---------- (cdr student)))

(map anonymous mid)

((---------- 2 14 17 5 14 52) (---------- 12 10 19 15 25 81) (---------- 21 19 19 19 18 96) (---------- 30 19 25 23 25 112) (---------- 11 19 12 17 23 82) (---------- 25 19 25 5 16 90) (---------- 12 20 25 13 22 92) (---------- 1 0 20 5 0 26) (---------- 17 20 17 15 23 92) (---------- 30 19 25 15 25 114) (---------- 30 20 25 15 25 120) (---------- 17 20 10 15 12 74) (---------- 6 17 18 18 11 70) (---------- 3 13 25 25 14 80) (---------- 12 20 25 19 25 101) (---------- 13 20 12 14 12 71) (---------- 3 12 14 5 5 39) (---------- 20 20 25 24 24 113) (---------- 15 20 12 21 2 70) (---------- 7 10 12 3 6 38) (---------- 3 10 12 5 0 30) (---------- 3 3 12 3 0 21) (---------- 30 20 25 25 25 125) (---------- 11 19 12 11 25 78) (---------- 2 20 19 13 23 77) (---------- 28 20 25 13 25 111) (---------- 27 20 25 5 25 102) (---------- 19 20 24 25 20 108) (---------- 3 19 14 0 14 50))

fields:5 problems, total score

Page 3: Computer Science 21b: Structure and Interpretation of ...mairson/Courses/cs21b/Lectures/Midt… · Computer Science 21b: Structure and Interpretation of Computer Programs Autumn Term,

(define (select n) (lambda (lst) (if (= n 0) (car lst) ((select (- n 1)) (cdr lst)))))

(map (select 6) mid)

Page 4: Computer Science 21b: Structure and Interpretation of ...mairson/Courses/cs21b/Lectures/Midt… · Computer Science 21b: Structure and Interpretation of Computer Programs Autumn Term,

(define (select n) (lambda (lst) (if (= n 0) (car lst) ((select (- n 1)) (cdr lst)))))

(map (select 6) mid)

(52 81 96 112 82 90 92 26 92 114 120 74 70 80 101 71 39 113 70 38 30 21 125 78 77 111 102 108 50)

Page 5: Computer Science 21b: Structure and Interpretation of ...mairson/Courses/cs21b/Lectures/Midt… · Computer Science 21b: Structure and Interpretation of Computer Programs Autumn Term,

(define (select n) (lambda (lst) (if (= n 0) (car lst) ((select (- n 1)) (cdr lst)))))

(map (select 6) mid)

(52 81 96 112 82 90 92 26 92 114 120 74 70 80 101 71 39 113 70 38 30 21 125 78 77 111 102 108 50)

(define (less fun) (lambda (x y) (< (fun x) (fun y))))

(define (sort lst fun) (define (insert item lst) (if (null? lst) (list item) (if ((less fun) item (car lst)) (cons item lst) (cons (car lst) (insert item (cdr lst)))))) (if (null? lst) '() (insert (car lst) (sort (cdr lst) fun))))

(map (select 6) (sort mid (select 6)))

Page 6: Computer Science 21b: Structure and Interpretation of ...mairson/Courses/cs21b/Lectures/Midt… · Computer Science 21b: Structure and Interpretation of Computer Programs Autumn Term,

(define (select n) (lambda (lst) (if (= n 0) (car lst) ((select (- n 1)) (cdr lst)))))

(map (select 6) mid)

(52 81 96 112 82 90 92 26 92 114 120 74 70 80 101 71 39 113 70 38 30 21 125 78 77 111 102 108 50)

(define (less fun) (lambda (x y) (< (fun x) (fun y))))

(define (sort lst fun) (define (insert item lst) (if (null? lst) (list item) (if ((less fun) item (car lst)) (cons item lst) (cons (car lst) (insert item (cdr lst)))))) (if (null? lst) '() (insert (car lst) (sort (cdr lst) fun))))

(map (select 6) (sort mid (select 6)))

(21 26 30 38 39 50 52 70 70 71 74 77 78 80 81 82 90 92 92 96 101 102 108 111 112 113 114 120 125)

purgatory begins somewhere in here

Page 7: Computer Science 21b: Structure and Interpretation of ...mairson/Courses/cs21b/Lectures/Midt… · Computer Science 21b: Structure and Interpretation of Computer Programs Autumn Term,

(define (roundoff x) (/ (round (* x 100)) 100.00))

(define (average problem) (let ((lst (map (select problem) mid)) (n (length mid))) (roundoff (/ (apply + lst) n))))

(define (half n) (if (even? n) (/ n 2) (/ (+ 1 n) 2)))

(define (median problem) (let ((lst (map (select problem) mid)) (n (length mid))) ((select (half n)) (sort lst (lambda (x) x)))))

Page 8: Computer Science 21b: Structure and Interpretation of ...mairson/Courses/cs21b/Lectures/Midt… · Computer Science 21b: Structure and Interpretation of Computer Programs Autumn Term,

(define (roundoff x) (/ (round (* x 100)) 100.00))

(define (average problem) (let ((lst (map (select problem) mid)) (n (length mid))) (roundoff (/ (apply + lst) n))))

(define (half n) (if (even? n) (/ n 2) (/ (+ 1 n) 2)))

(define (median problem) (let ((lst (map (select problem) mid)) (n (length mid))) ((select (half n)) (sort lst (lambda (x) x)))))

(map average '(1 2 3 4 5 6))

(14.24 16.62 18.97 13.48 16.69 79.83)

(map median '(1 2 3 4 5 6))

(13 19 19 15 22 82)

Page 9: Computer Science 21b: Structure and Interpretation of ...mairson/Courses/cs21b/Lectures/Midt… · Computer Science 21b: Structure and Interpretation of Computer Programs Autumn Term,

(map (lambda (n) (sort (map (select n) mid) (lambda (x) x))) '(1 2 3 4 5 6))

((1 2 2 3 3 3 3 3 6 7 11 11 12 12 12 13 15 17 17 19 20 21 25 27 28 30 30 30 30)

(0 3 10 10 10 12 13 14 17 19 19 19 19 19 19 19 20 20 20 20 20 20 20 20 20 20 20 20 20)

(10 12 12 12 12 12 12 12 14 14 17 17 18 19 19 19 20 24 25 25 25 25 25 25 25 25 25 25 25)

(0 3 3 5 5 5 5 5 5 11 13 13 13 14 15 15 15 15 15 17 18 19 19 21 23 24 25 25 25)

(0 0 0 2 5 6 11 12 12 14 14 14 16 18 20 22 23 23 23 24 25 25 25 25 25 25 25 25 25)

(21 26 30 38 39 50 52 70 70 71 74 77 78 80 81 82 90 92 92 96 101 102 108 111 112 113 114 120 125))