-
Notifications
You must be signed in to change notification settings - Fork 0
/
2-12.rkt
39 lines (26 loc) · 892 Bytes
/
2-12.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#lang racket
(define (percent->float p)
(* p 0.01))
(define (float->percent n)
(* n 100))
;;
(define (make-interval a b) (cons a b))
(define (lower-bound interval) (car interval))
(define (upper-bound interval) (cdr interval))
(define (make-center-width c w)
(make-interval (- c w) (+ c w)))
(define (center int)
(/ (+ (lower-bound int) (upper-bound int)) 2))
(define (width int)
(/ (- (upper-bound int) (lower-bound int)) 2))
;; p - percentage value 0-100
(define (make-center-percent c p)
(make-interval (- c (percent->float (* c p)))
(+ c (percent->float (* c p)))))
(define (percentage-tolerance-interval int)
(let ([center (center int)]
[lower (lower-bound int)])
(float->percent (/ (- center lower) center))))
(define tolerance 50)
(define int (make-center-percent 50 tolerance))
(= (percentage-tolerance-interval int) tolerance)