;;; Attempts to write close
;;; close1? is closely based on code by Michael Billups that was written
;;; in response to a question on exam 1.
(define close1?
(lambda (num1 num2)
(if
(< num1 num2)
(if
(<= (- num2 num1) (* #e.01 num2))
#t
#f)
(if
(<= (- num1 num2) (* #e.01 num1))
#t
#f))))
; Sam doesn't like returning #t, #f
; Works for 0
; Does it work for negative numbers? No
; Awkward formatting. Make sure to write the test on the same line as the if.
(define close1?
(lambda (num1 num2)
(if (< num1 num2)
(if (<= (- num2 num1) (* #e.01 num2))
#t
#f)
(if (<= (- num1 num2) (* #e.01 num1))
#t
#f))))
(define close2?
(lambda (num1 num2)
(if (or (<= .99 (/ (abs num1) (abs num2)) 1)
(<= .99 (/ (abs num2) (abs num1)) 1))
#t
#f)))
; Once again, the joy of returning #t and #f
(define close2?
(lambda (num1 num2)
(or (<= .99 (/ (abs num1) (abs num2)) 1)
(<= .99 (/ (abs num2) (abs num1)) 1))))
; Works for both negative. Yay!
; Cannot handle 0. Boo!
; Considers 100 and -100 close to each other. Boo hoo!