1 day ago
my attempt to do the exercises in sicp.
Wednesday, July 16, 2008
sicp exercise 2.25
; Exercise 2.25. Give combinations of cars and cdrs that will pick 7 from each of the following lists:
; (1 3 (5 7) 9)
; ((7))
; (1 (2 (3 (4 (5 (6 7))))))
(define x '(1 3 (5 7) 9))
(define xx (list 1 3 (list 5 7) 9) )
(define y '((7)))
(define yy (list (list 7)))
(define z '(1 (2 (3 (4 (5 (6 7)))))))
(define zz (list 1 (list 2 (list 3 (list 4 (list 5 (list 6 7)))))))
(display x) (newline)
(display xx) (newline)
(display y) (newline)
(display yy) (newline)
(display z) (newline)
(display zz) (newline)
(display (car ( cdr ( car (cdr (cdr xx)))))) (newline)
(display ( car ( car yy))) (newline)
(display (car (cdr (car (cdr (car (cdr (car (cdr (car (cdr (car (cdr zz))))))))))))) (newline)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment