yon


Joined 2 years ago
Homeworks submitted:
Homework comments:
1
0

About Me

No description provided.

Classes

Structure and Interpretation of Computer Programs

Class status: Established
Role: Student
. 7% complete

Submitted Assignments

Structure and Interpretation of Computer Programs: Lesson 1, HW 1

Ex 1.1 10 12 8 3 6 no output no output 19 #f 4 16 6 16

Ex 1.4 If b is positive, it adds a and b. If b is negative, it subtracts b from a. This is equivalent to a+|b|

Ex 1.5 Applicative order: Infinite loop (p calls p repeatedly) Normal order: 0 (p never actually evaluated)

Ex 1.6 Because of applicative order, all arguments are evaluated. Thus, (sqrt-iter (improve guess x) x) will be evaluated no matter what. Therefore, the program enters an infinite loop, as the new call to sqrt-iter will do the same.

Ex 1.2
	(/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 8))))) (* 3 (- 6 2) (- 2 7)))

Ex 1.3
	(define (f a b c) (if (and (< a b) (< a c)) (+ (* b b) (* c c)) (+ (* a a) (if (< b c) (* c c) (* b b)))))

Ex 1.7
	(define (good-enough? guess last) (and (> 1.001 (/ guess last)) (> 1.001 (/ last guess))))
	(define (sqrt-iter guess last x)
	  (if (good-enough? guess last)
	      guess
	      (sqrt-iter (improve guess x) guess
                 x)))
        (define (sqt x)
	  (sqrt-iter 1.0 2.0 x))
	  
Ex 1.8
	(define (improve-curt guess x) (/ (+ (/ x (square guess)) (* 2 guess)) 3))
	(define (curt x)
		(curt-iter 1.0 2.0 x))
	(define (curt-iter guess last x)
		(if (good-enough? guess last x)
		guess
		(curt-iter (improve-curt guess x) guess x)))
		

yon 2 years ago