Skip to content

Instantly share code, notes, and snippets.

@kouddy
Last active August 29, 2015 14:18
Show Gist options
  • Save kouddy/de009353a2da0ed623b8 to your computer and use it in GitHub Desktop.
Save kouddy/de009353a2da0ed623b8 to your computer and use it in GitHub Desktop.
(define (make-interval a b) (cons a b))
(define (lower-bound i) (car i))
(define (upper-bound i) (cdr i))
;;; c is the center
;;; n is the percentage
(define (make-center-percent c n)
(let ((w (* c (/ n 100)))) ;;; convert percentage to width
(make-center-width c w)))
(define (percent i)
(* (/ (width i) (center i)) 100))
(define (make-center-width c w)
(make-interval (- c w) (+ c w)))
(define (center i)
(/ (+ (lower-bound i) (upper-bound i)) 2))
(define (width i)
(/ (- (upper-bound i) (lower-bound i)) 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment