Added lisp along with some study work
This commit is contained in:
23
lisp/land-of-lisp/ch2/guess-my-number-game.lisp
Normal file
23
lisp/land-of-lisp/ch2/guess-my-number-game.lisp
Normal file
@@ -0,0 +1,23 @@
|
||||
(defparameter *small* 1)
|
||||
(defparameter *big* 100)
|
||||
|
||||
(defun guess-my-number ()
|
||||
;; ash is the artithmetic shift function
|
||||
;; Halvs the sum of the limits and shortens the result
|
||||
;; ash, here, shifts the binary bits left or right (well, right in this case)
|
||||
;; Which leads to the right most binary falling off
|
||||
;; This is a binary search
|
||||
(ash (+ *small* *big*) -1))
|
||||
|
||||
(defun smaller ()
|
||||
(setf *big* (1- (guess-my-number)))
|
||||
(guess-my-number))
|
||||
|
||||
(defun bigger ()
|
||||
(setf *small* (1+ (guess-my-number)))
|
||||
(guess-my-number))
|
||||
|
||||
(defun start-over ()
|
||||
(defparameter *small* 1)
|
||||
(defparameter *big* 100)
|
||||
(guess-my-number))
|
||||
Reference in New Issue
Block a user