Before you tackle the homework, remind yourself of our General Advice, Advice on Homeworks, and Grading Guidelines. Above all, keep your work neat and honest.
Note: For the following problems, you may not use Scheme's built-in abstract functions, such as filter, map, and fold. If you wish, you may define and use your own versions of these functions; you are not, however, required to do this.
(define (only-two-syms? sym1 sym2 alos) (cond [(empty? alos) true] [else (and (or (symbol=? sym1 (first alos)) (symbol=? sym2 (first alos))) (only-two-syms? sym1 sym2 (rest alos)))])) (define (all-alive? aloc) (cond [(empty? aloc) true] [else (and (> (character-lives (first aloc)) 0) (all-alive? (rest aloc)))]))
(3 pts) Write an abstract program that captures both of these definitions.
(2 pts) Provide new definitions of only-two-syms? and all-alive? in terms of your abstract program.
(define (double-last alon) (cond [(empty? (rest alon)) (* 2 (first alon))] [else (double-last (rest alon))])) ;; The function max is built-in in DrScheme (define (max-of-list alon) (cond [(empty? (rest alon)) (first alon)] [else (max (first alon) (max-of-list (rest alon)))]))
(3 pts) Write an abstract program that captures both of these definitions.
(2 pts) Provide new definitions of double-last and max-of-list in terms of your abstract program.
Kathi Fisler | This page was generated on Wed Oct 13 11:18:11 CDT 1999. |