View Question
Q: Help with Checking Excercise Soultions ( Answered ,   0 Comments )
 Question
 Subject: Help with Checking Excercise Soultions Category: Computers > Programming Asked by: mott85-ga List Price: \$10.00 Posted: 05 Oct 2004 21:02 PDT Expires: 04 Nov 2004 20:02 PST Question ID: 410901
 ```I am trying to teach myself scheme so I have the book Structure and interpretation of computer programs Second edition by Harold Abelson and Gerald Jay Sussman. I have done some sample exercises however this book provides no answers to check myself. Is there somewhere I can get the answers to exercises: Exercise 2.2 Exercise 2.30 Exercise 2.36 Exercise 2.37 ? I would like to see if I am on the right track. Thanks``` Request for Question Clarification by googleexpert-ga on 06 Oct 2004 06:47 PDT ```Hi mott85-ga, I am familiar with the book "Structure and Interpretation of Computer programs" and know how difficult most of the exercises are. However, there are some exercises that are somewhat easy given any prerequisite knowledge. Is there an exercise you are sure of the answer to, just so I know this is not a homework problem? Thanks. -googleexpert``` Clarification of Question by mott85-ga on 06 Oct 2004 22:31 PDT ```Thank you for checking to see why i need this. I do understand basic concepts. For exemple excercise 2.2 i pretty sure i solved correctly here si the code: (define (same-parity x . r) (define (helper proc lst result) (if (null? lst) result (helper proc (cdr lst) (if (proc (car lst)) (append result (list (car lst))) result)))) (if (even? x) (helper even? r (list x)) (helper odd? r (list x)))) I was also able to solve 2.17 amd 2.23 i was just wnat to check my thoughts on the ones i listed i would apprecite if some can show me where a proper soultion is for those.```
 ```Hi again mott85-ga, Here are the solutions to exercises ( 2.2, 2.30, 2.36, 2.37 ): Exercise 2.2: Source: http://t2.technion.ac.il/~seyal18/Chapter2/ex2-2.txt (define (make-segment sp ep) (cons sp ep)) (define (start-segment segment) (car segment)) (define (end-segment segment) (cdr segment)) (define (make-point x y) (cons x y)) (define (x-point point) (car point)) (define (y-point point) (cdr point)) ;;; calc midpoint ;;; midpoint x - (x1 + x2)/2 the same with y (define (midpoint-segment line) (make-point (/ (+ (x-point (start-segment line)) (x-point (end-segment line))) 2) (/ (+ (y-point (start-segment line)) (y-point (end-segment line))) 2))) (define (print-point p) (newline) (display ")") (display (x-point p)) (display ",") (display (y-point p)) (display ")")) Exercise 2.30 Source: http://www.cis.udel.edu/~mccoy/courses/cisc280-04s/Homeworks/hw3/hw3-answers.scm (define (square x) (* x x)) ;; Direct implementation ;; Takes a tree of numbers represented as a list ;; returns the tree of numbers where each number ;; in the original tree has been squared (define (square-tree tree) (cond ((null? tree) ()) ((not (pair? (car tree))) (cons (square (car tree)) (square-tree (cdr tree)))) (else (cons (square-tree (car tree)) (square-tree (cdr tree)))))) ;; Map implementation ;; Takes a tree of numbers represented as a list ;; returns the tree of numbers where each number ;; in the original tree has been squared (define (map-square-tree tree) (map (lambda (sub-tree) (if (pair? sub-tree) (map-square-tree sub-tree) (square sub-tree))) tree)) Exercise 2.36 Source: http://www.cis.udel.edu/~mccoy/courses/cisc280-04s/Homeworks/hw4/hw4-answers.scm (define (accumulate-n op init seqs) (if (null? (car seqs)) () (cons (accumulate op init (map car seqs)) (accumulate-n op init (map cdr seqs))))) Exercise 2.37 Source: http://www.cis.udel.edu/~mccoy/courses/cisc280-04s/Homeworks/hw4/hw4-answers.scm (define v1 '(1 2 3)) (define v2 '(4 5 6)) (define m2 '((1 2 3) (4 5 6) (7 8 9))) (define v3 '(2 3 4)) (define v4 '(10 13 16)) (define a '((1 -2 2) (1 0 2))) (define b '((1 0 1) (3 -1 5) (4 2 0))) ;(matrix-*-matrix a b) ;=((3 6 -9) (9 4 1)) (define e1 '((1 0 -2) (0 3 -1))) (define e2 '((0 3) (-2 -1) (0 4))) ;(matrix-*-matrix e1 e2) ;=((0 -5) (-6 -7)) ; dot-product takes two vectors and returns the ; sum of their pairwise multiplication (define (dot-product v w) (accumulate + 0 (map * v w))) ; takes a matrix and a vector and returns a ; vector where each ti in the vector is the ; sum of mij*vj (for all j) (define (matrix-*-vector m v) (map (lambda (w) (dot-product v w)) m)) ; takes a matrix and returns its transpose ; the transpose of a matrix, mat, is another ; matrix trans-mat where trans-mat(i,j)=mat(j,i) (define (transpose mat) (accumulate-n cons () mat)) ; takes two matrices and multiplies them together ; it returns the matrix result where ; retult(i,j)=sum of k or m(i,k)*n(k,j) (define (matrix-*-matrix m n) (let ((cols (transpose n))) (map (lambda (v1) (map (lambda (c1) (dot-product c1 v1)) cols)) m))) [Search Strategy] Used keywords from Textbook exercises and scheme keywords. Please let me know if you have anymore questions. Thanks again. -googleexpert``` Clarification of Answer by googleexpert-ga on 09 Oct 2004 18:45 PDT ```Thank you very much for 5-Star rating! I appreciate it .:)```