This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Number guessing, the other way

By: a guest on Feb 10th, 2012  |  syntax: Lisp  |  size: 0.41 KB  |  views: 101  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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)
clone this paste RAW Paste Data