Computer Science 61A - Spring 2006 - Harvey - Midterm 1 Solutions

Computer Science 61A - Spring 2006 - Harvey - Midterm 1 Solutions

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon 1 of 6 5/11/2006 12:10 AM CS 61A Fall 2005 Midterm #1 solutions Note: If your individual score is I points (out of 40) and your group score is G points (out of 12), your overall score will be computed as (max I (+ (* 0.91666667 I) (* 0.3333 G))) The theory behind this formula is that 20 of your 40 individual points are not matched by anything in the group exam, and for the 10 points that are matched, we want to weight the exams as 2/3 individual, 1/3 group. So that gives (+ (* 30/40 I) (* 2/3 (* 10/40 I)) (* 1/3 G)), except that if your individual score is better than the combined score by this formula, we'll keep your individual score. But this correction is done at the end of the semester in the final grade-reporting program; GLOOKUP isn't smart enough to report anything but a fixed weighting of points. 1. What will Scheme print? Scoring: One point each, all or nothing, except that we deducted at most one point for quotation marks before/around any number of otherwise correct answers. *You* type quotation marks in front of sentences you want Scheme to treat as data rather than as procedure calls, but THE QUOTATION MARKS ARE NOT PART OF THE VALUES, AND SCHEME DOESN'T PRINT THEM. 1) > (keep (lambda (x) (or (even? x) (< (count x) 3))) '(1 12 123)) (1 12) (EVEN? X) is true for 12; (< (COUNT X) 3) is true for 1 and 12. So the (OR . ..) is true for 1 and 12. 2) > (se '(procedures are) (first 'class)) (procedures are c) (FIRST 'CLASS) is its first letter, C. 3) > (every (* x x) '(4 5 6)) ERROR (unbound symbol x) The answer (16 25 36) would be correct if the question were (every (LAMBDA (X) (* x x)) '(4 5 6)) but in the actual question, the first argument to EVERY isn't a function; it's an attempt to compute the square of some particular number called X, and there isn't any such variable. 4) > (every first (keep even? '(23 48 12 87 6))) (4 1 6) The (KEEP . ..) part returns (48 12 6), and so (EVERY . ..) returns the first digits of each of those numbers. It's okay that 6 has only one digit; that just means that its last is the same as its first. And it's okay that 1 isn't even; 12 is even, and the KEEP testing happens before we take FIRST of anything. 5) > (word (first '(wish you)) (bf '(were here))) ERROR (Invalid argument to WORD: (HERE).) (BF '(WERE HERE)) is the sentences (HERE), not the word HERE. That would be (LAST '(WERE HERE)). So this expression gives the WORD procedure a sentence as its second argument. 6) > (cond ('comfortably 'numb) (hey you) (else money)) numb The first COND clause is ('comfortably 'numb). Since anything other than #F is considered true in Scheme, the word COMFORTABLY is true, and so the expression 'NUMB is evaluated to provide the return value for the COND. The remaining clauses are not evaluated, so it doesn't matter than HEY is an unbound variable.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/01/2008 for the course CS 61A taught by Professor Harvey during the Spring '08 term at University of California, Berkeley.

Page1 / 6

Computer Science 61A - Spring 2006 - Harvey - Midterm 1 Solutions

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online