Advertisement
Guest User

Untitled

a guest
May 25th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.82 KB | None | 0 0
  1. (defvar *maximum* 100)
  2. (defvar *minimum* 1)
  3.  
  4. (defun reset ()
  5.   "Resets the minimum and maximum values"
  6.   (format t "Okay, let's reset!~%")
  7.   (setf *maximum* 100)
  8.   (setf *minimum* 1)
  9.   (guess))
  10.  
  11. (defun average (initial &rest remaining)
  12.   "Gets the average of the values, requiring at least the intial value"
  13.   (let* ((all (cons initial remaining))
  14.          (len (length all))
  15.          (sum (apply #'+ all)))
  16.     (floor sum len)))
  17.  
  18. (defun higher ()
  19.   "Sets the maximum to the average and guesses again"
  20.   (setf *minimum* (average *maximum* *minimum*))
  21.   (guess))
  22.  
  23. (defun lower ()
  24.   "Sets the average to the minimum and guesses again"
  25.   (setf *maximum* (average *maximum* *minimum*))
  26.   (guess))
  27.  
  28. (defun guess ()
  29.   "Prints a guess based on the average"
  30.   (format t "I'm guessing ~a~%" (average *maximum* *minimum*)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement