Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Code Block
;; contract:
;; within-two?: num num --> boolean
;;
;; purpose: Returns true if two numbers are within 2 of
;; each other, that is, returns true if m - n and n - m
;; are both less than 2.
;;
;; Examples:
(check-expect (within-two? 99.8 101) true)
(check-expect (within-two? 101 99.8) true)
(check-expect (within-two? 5 -5)     false)
(check-expect (within-two? -5 5)     false)
(check-expect (within-two? 5 3)     false)
(check-expect (within-two? 3 5)     false)
(check-expect (within-two? 42 42)     true)
;;
;;Definition:
(define (within-two? m n)
  (and (< (- m n) 2) (< (- n m) 2)))