Simple Number Guessing Game

Discussion of Common Lisp

Simple Number Guessing Game

Postby GengyangCai » Fri Jul 03, 2015 8:36 am

This is a simple number guessing game written in Lisp :

(defparameter *small* 1)
(defparameter *big* 100)

(defun guess-my-number ()
(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))

Output :

CL-USER 41 > (defparameter *small* 1)
*SMALL*

CL-USER 42 > (defparameter *big* 100)
*BIG*

CL-USER 43 >
(defun guess-my-number ()
(ash (+ *small* *big*) -1))
GUESS-MY-NUMBER

CL-USER 44 >
(defun smaller ()
(setf *big* (1- (guess-my-number)))
(guess-my-number))
SMALLER

CL-USER 45 >
(defun bigger ()
(setf *small* (1+ (guess-my-number)))
(guess-my-number))
BIGGER

CL-USER 46 >
(defun start-over ()
(defparameter *small* 1)
(defparameter *big* 100)
(guess-my-number))
START-OVER

:)
GengyangCai
 
Posts: 13
Joined: Sun Jul 08, 2012 3:50 pm

Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 1 guest