Lisp GCD and Fibonacci functions by Shane Zentz



; Shane Zentz
; C-311
; Homework # 4
; 9-20-2007

(defun GDC (n m)
"This function returns the greatest common divisor of two arguments"
(if (< n m)
(GDC m n))
(setq a n)
(setq b m)
(setq r 1)
(while (not (= r 0))
(setq r (% a b))
(setq a b)
(setq b r))a)
GDC

(defun is-in (L x)
"This function determines if an element is in the list"
(setq found nil)
(dolist (m L found)
(if (equal x m)
(setq found t))))
is-in

(defun fibonichi (n)
"This function returns a list with the first n numbers of fibonichi series"
(setq x 1)(setq y 1)(setq z 0)
(setq L '(1 1))
(dotimes (counter (- n 2) L)
(setq z (+ x y))
(push z L)
(setq y x)
(setq x z)))
fibonichi

(setq days '(Monday Tuesday Wednesday thursday fRiday))
(Monday Tuesday Wednesday thursday fRiday)

(setq nums '(0 1 2 3 4 5))
(0 1 2 3 4 5)

(GDC 5 100)
5

(GDC 100 25)
25

(is-in nums 9)
nil

(is-in nums 4)
t

(is-in days 'thursday)
t

(is-in days 'hello)
nil

(fibonichi 5)
(5 3 2 1 1)

(fibonichi 14)
(377 233 144 89 55 34 21 13 8 5 3 2 ...)

(fibonichi 12)
(144 89 55 34 21 13 8 5 3 2 1 1)

(fibonichi 2)
(1 1)