Advertisement
Guest User

Number guessing, the other way

a guest
Feb 10th, 2012
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.41 KB | None | 0 0
  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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement