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)
  (and (< (- m n) 2)
       (< (- n m) 2)))

'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
Teaching.210lab01-within-two1 moved from Teaching.210lab02-within-two1 on 12 Sep 2007 - 20:29 by ChrisWarrington - put it back
Creative Commons LicenseThis work is licensed under a Creative Commons Attribution 2.5 License. Please follow our citation guidelines.