daily pastebin goal
66%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 61 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #lang racket
  2. ;;----------------------------------------------ZAD 1----------------------------------------------
  3. (define/contract (suffixes l)
  4.   (let ((a (new-∀/c 'a)))
  5.     (-> (listof a) (listof (listof a))))
  6.    (if (null? l)
  7.        '()
  8.        (cons l (suffixes (cdr l)))))
  9.  
  10. ;;----------------------------------------------ZAD 2----------------------------------------------
  11. (define/contract (dist x y)
  12.   (-> number? number? number?)
  13.   (abs (- x y)))
  14.  
  15. (define/contract (average x y)
  16.   (-> number? number? number?)
  17.   (/ (+ x y) 2))
  18.  
  19. (define/contract (square x)
  20.   (-> number? number?)
  21.   (* x x))
  22.  
  23. (define/contract (sqrt x)
  24.   (->i ((argument (>=/c 0)))
  25.        (result (argument) (and/c (>=/c 0)
  26.                                  (if (> argument 1)
  27.                                      (<=/c argument)
  28.                                      (>=/c argument)))))
  29.   ;; lokalne definicje
  30.   ;; poprawienie przybliżenia pierwiastka z x
  31.   (define (improve approx)
  32.     (average (/ x approx) approx))
  33.   ;; nazwy predykatów zwyczajowo kończymy znakiem zapytania
  34.   (define (good-enough? approx)
  35.     (< (dist x (square approx)) 0.0001))
  36.   ;; główna procedura znajdująca rozwiązanie
  37.   (define (iter approx)
  38.     (cond
  39.       [(good-enough? approx) approx]
  40.       [else                  (iter (improve approx))]))
  41.  
  42.   (iter 1.0))
  43.  
  44.  
  45. ;;----------------------------------------------ZAD 3----------------------------------------------
  46. (define/contract (filter l p)
  47.   (-> (and/c
  48.        (let ((a (new-∀/c 'a)))
  49.          (-> (listof a) (-> a boolean?) (listof a)))
  50.        (->i ([l list?] [p procedure?])
  51.             [result (l) (λ (r) (<= (length r) (length l)))])))
  52.   (if (null? l)
  53.       '()
  54.       (if (p (car l))
  55.           (cons (car l) (filter (cdr l) p))
  56.           (filter (cdr l) p))))
  57.  
  58.  
  59. ;;----------------------------------------------ZAD 4----------------------------------------------
  60. (define-signature monoid^
  61.   ((contracted
  62.     [elem? (-> any/c boolean?)] [neutral elem?]
  63.     [oper (-> elem? elem? elem?)])))
  64.  
  65.  
  66.  
  67. ;;----------------------------------------------ZAD 5----------------------------------------------
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top