;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 21questions.lisp ;; Lee Spector (defun 21questions () (format t "~%I'm thinking of something...") (format t "~%You have 21 questions to guess what it is.") (format t "~%Ask whatever YES OR NO questions you want --") (format t "~%I understand English perfectly!") (let ((questions 1)) (loop (when (> questions 21) (format t "~%Sorry, you didn't get it. Bye!") (return (values))) (format t "~%Question ~A? " questions) (case (number-of-trailing-spaces (read-line t nil)) (0 (format t "~%NO")) (1 (format t "~%YES")) (t (format t "~%You got it! Good job!") (return (values)))) (incf questions)))) (defun number-of-trailing-spaces (string) "Returns the number of space characters at the end of string." (or (position-if-not #'(lambda (c) (eq c #\space)) (reverse string)) 0))