Advertisement
Guest User

Lista 1 z MP

a guest
Apr 23rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 0.99 KB | None | 0 0
  1. #lang racket
  2.  
  3. ;; ćw. 4
  4.  
  5. (define (square x) (* x x))
  6.  
  7. (define (sum-of-squares x y) (+ (square x) (+ (square y))))
  8.  
  9. (define (sum-of-greater x y z)
  10.   (cond [(and (> x z) (> y z)) (sum-of-squares x y)]
  11.         [(and (> x y) (> z y)) (sum-of-squares x z)]
  12.         [else (sum-of-squares y z)]))
  13.  
  14. ;; ćw. 6
  15.  
  16. (define ex-for-and
  17.   (and (< 10 3) (= 2 (/ 4 0))))
  18.  
  19. (define ex-for-or
  20.   (or (= 2 2) (= 0 (/ 12 0))))
  21.  
  22. ;; ćw. 7
  23.  
  24. (define (power-close-to b n)
  25.   (define (wykladnik e)
  26.     (if (> (expt b e) n)
  27.         e
  28.         (wykladnik (+ e 1))))
  29.   (wykladnik 0))
  30.  
  31.  
  32. ;; pracownia
  33.  
  34. (define (cube x) (* x x x))
  35.  
  36.  (define (aux x y)
  37.    (/ (+ x (* 2 (cube y))) (* 3 (square y))))
  38.  
  39. (define (dist x y)
  40.   (abs (- x y)))
  41.  
  42. (define (cube-root x)
  43.   (define (improve approx)
  44.     (aux x approx))
  45.   (define (good-enough? approx)
  46.     (< (dist x (cube approx)) 0.0001))
  47.   (define (iter approx)
  48.     (if (good-enough? approx)
  49.         approx
  50.         (iter (improve approx))))
  51.  
  52.   (iter 1.0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement