cs61a_final_su01 - UNIVERSITY of CALIFORNIA at Berkeley...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: UNIVERSITY of CALIFORNIA at Berkeley Department of Electrical Engineering and Computer Sciences Computer Sciences Division CS 61A Summer Session 2001 Final Exam August 17, 2001 Your name login: cs61a Section number TAs name This exam contains 9 questions, plus the following: Question 0 (1 point): Fill out this front page correctly and put your name and login correctly at the top of each of the following pages. This booklet contains 10 numbered pages including the cover page. Please put all answers on these pages. Dont hand in stray pieces of paper. This is an open book/open note exam. Use of computers or calculators is prohibited. When writing procedures, dont put in error checks. Assume that you will be given arguments of the correct type. This exam is worth 60 points, or about 20% of your total course grade. Our expectation is that many of you will not complete one or two of these questions. If you find one question especially difficult, leave it for later; start with the ones you find easier. You have three hours to complete this test. By signing below, you certify that your answers to this exam are all your own work, and that you have not discussed the exam questions or answers with anyone prior to taking this exam. Signature: Question Points Score 1 1 6 2 6 3 7 4 6 5 6 6 7 7 9 8 7 9 6 Total 60 1 Your name login cs61a Question 1 (7 points): 1a. Recall filter and accumulate : STk> (filter (lambda (x) (< x 5)) (list 3 4 5 6 7)) (3 4) STk> (accumulate + 0 (list 1 2 3 4)) 10 Write filter in terms of accumulate. DO NOT write any helper procedures. Fill in the blanks only. (define (filter f lst) (accumulate )) 1b. Write a procedure all-true? that takes a list of #t s and #f s and returns #t if all elements in the list is #t ; #f if any of the element is #f . Use higher order procedures. Do not write any helper procedures! Example: STk> (all-true? (#t #t #t #t)) #t STk> (all-true? (#t #t #f #t)) #f Fill in the following blank: (define (all-true? lst) ) (continued on next page) 2 Your name login cs61a 1c. We want to write a function called the-most that takes a comparison function (a predicate that takes 2 arguments) and returns another function. the-most returns a function that accepts a non-empty list as its argument and returns the most element of the list, according to that predicate. Here is a sample interaction: STk> (define maximum (the-most >)) maximum STk> (maximum (7 20 3 30 1 9)) 30 STk> (define minimum (the-most <)) minimum STk> (minimum (7 20 3 30 1 9)) 1 Define the function the-most as a recursive procedure that evolves an iterative process. 3 Question 2 (6 points): Write a program in the nondeterministic evaluator to find positive integer solutions to the following equation, known as Pells equation: x 2- Ay 2 = 1 That is, your program pell takes a value A , and generates positive integers x and y that satisfy the equation....
View Full Document

This note was uploaded on 09/02/2010 for the course COMPSCI N/A taught by Professor Various during the Summer '01 term at University of California, Berkeley.

Page1 / 14

cs61a_final_su01 - UNIVERSITY of CALIFORNIA at Berkeley...

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

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