SHARE
TWEET

Number guessing, the other way

a guest Feb 10th, 2012 178 Never
  1. (defun guess (min max)
  2.   (let ((guess (round (/ (+ min max) 2))))
  3.     (format t "My guess: ~a. Is your number (l)ower, (h)igher or (e)qual to this? " guess)
  4.     (let ((answer (read-line)))
  5.       (cond ((equalp answer "l") (guess min (1- guess)))
  6.             ((equalp answer "h") (guess (1+ guess) max))
  7.             ((equalp answer "e") (format t "Yeah!~%"))
  8.             (t (guess min max))))))
  9.  
  10. (guess 0 100)
RAW Paste Data
Top