Skip to content

Instantly share code, notes, and snippets.

@yakreved
Created August 13, 2013 23:30
Show Gist options
  • Save yakreved/6226723 to your computer and use it in GitHub Desktop.
Save yakreved/6226723 to your computer and use it in GitHub Desktop.
sicp 2.13
(define (make-interval a b) (cons a b))
(define (upper-bound x) (car x))
(define (lower-bound x) (cdr x))
(define (width x) (- (cdr x) (car x)))
(define (center i)
(/ (+ (lower-bound i) (upper-bound i)) 2))
(define (make-center-percent c p)
(let ((w (* c (/ p 100))))
(make-interval (- c w) (+ c w))))
(define (percent x)
(abs (* 100 (/ (- (upper-bound x) (lower-bound x)) (+ (upper-bound x) (lower-bound x)))))
)
(define (mul-percent x y)
(abs (* 100 (+ (/ (width x) (center x)) (/ (width x) (center y)))))
)
(mul-percent (make-interval 95 105) (make-interval 95 105))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment