Start of topic | Skip to actions

Solution: within-two?

; within-two?: number, number -> boolean
; Purpose: Returns whether m,n are less than 2 apart.
; A difference of exactly 2 returns false.
;
(define (within-two? m n)
  (cond [(>= (- m n) 2) false]
        [(>= (- n m) 2) false]
        [else           true]))

'within-two?_examples
(boolean=? (within-two? 99.8 101) true)
(boolean=? (within-two? 5 -5)     false)
(boolean=? (within-two? 7 7)      true)

Access Permissions


End of topic
Skip to actions | Back to top
Creative Commons LicenseThis work is licensed under a Creative Commons Attribution 2.5 License. Please follow our citation guidelines.