To be noted: the last two exercises, 2.15 and 2.16 were left unfinished, and will be left for another time.
23 lines
420 B
Scheme
23 lines
420 B
Scheme
#lang sicp
|
|
|
|
(define (make-interval a b) (cons a b))
|
|
|
|
(define (lower-bound i)
|
|
(car i))
|
|
|
|
(define (upper-bound i)
|
|
(cdr i))
|
|
|
|
|
|
(define (make-center-percent c p)
|
|
(make-interval (- c (* c p 1/100))
|
|
(+ c (* c p 1/100))))
|
|
|
|
(define (center i)
|
|
(/ (+ (lower-bound i) (upper-bound i)) 2))
|
|
|
|
(define (width i)
|
|
(/ (- (upper-bound i) (lower-bound i)) 2))
|
|
|
|
(define (percent i)
|
|
(* (/ (width i) (center i)) 100))
|