; a simple interview question
(define (add1 x) (+ x 1))
(define (sub1 x) (- x 1))
(define (sum x y)
(while (< x 0) (set! x (add1 x)) (set! y (sub1 y)))
(while (< 0 x) (set! x (sub1 x)) (set! y (add1 y)))
y)
(display (sum 3 5)) (newline)
(display (sum 3 -5)) (newline)
(display (sum -3 5)) (newline)
(display (sum -3 -5)) (newline)
OyBhIHNpbXBsZSBpbnRlcnZpZXcgcXVlc3Rpb24KCihkZWZpbmUgKGFkZDEgeCkgKCsgeCAxKSkKKGRlZmluZSAoc3ViMSB4KSAoLSB4IDEpKQoKKGRlZmluZSAoc3VtIHggeSkKICAod2hpbGUgKDwgeCAwKSAoc2V0ISB4IChhZGQxIHgpKSAoc2V0ISB5IChzdWIxIHkpKSkKICAod2hpbGUgKDwgMCB4KSAoc2V0ISB4IChzdWIxIHgpKSAoc2V0ISB5IChhZGQxIHkpKSkKICB5KQoKKGRpc3BsYXkgKHN1bSAzIDUpKSAobmV3bGluZSkKKGRpc3BsYXkgKHN1bSAzIC01KSkgKG5ld2xpbmUpCihkaXNwbGF5IChzdW0gLTMgNSkpIChuZXdsaW5lKQooZGlzcGxheSAoc3VtIC0zIC01KSkgKG5ld2xpbmUp