Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- ;; ćw. 4
- (define (square x) (* x x))
- (define (sum-of-squares x y) (+ (square x) (+ (square y))))
- (define (sum-of-greater x y z)
- (cond [(and (> x z) (> y z)) (sum-of-squares x y)]
- [(and (> x y) (> z y)) (sum-of-squares x z)]
- [else (sum-of-squares y z)]))
- ;; ćw. 6
- (define ex-for-and
- (and (< 10 3) (= 2 (/ 4 0))))
- (define ex-for-or
- (or (= 2 2) (= 0 (/ 12 0))))
- ;; ćw. 7
- (define (power-close-to b n)
- (define (wykladnik e)
- (if (> (expt b e) n)
- e
- (wykladnik (+ e 1))))
- (wykladnik 0))
- ;; pracownia
- (define (cube x) (* x x x))
- (define (aux x y)
- (/ (+ x (* 2 (cube y))) (* 3 (square y))))
- (define (dist x y)
- (abs (- x y)))
- (define (cube-root x)
- (define (improve approx)
- (aux x approx))
- (define (good-enough? approx)
- (< (dist x (cube approx)) 0.0001))
- (define (iter approx)
- (if (good-enough? approx)
- approx
- (iter (improve approx))))
- (iter 1.0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement