-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhw1.lisp
48 lines (43 loc) · 1.01 KB
/
hw1.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
; Chris Durtschi
; CS4500 Artificial Intelligence
; Ron Peterson
; LISP Homework 1
(defun drev (src dest)
"Construct a list, moving elements of src to dest"
(cond
((null src) dest)
(t (drev (rest src) (cons (first src) dest)))
)
)
(defun rev (lst)
"Takes a list and returns the atoms in reverse order"
(drev lst nil)
)
(defun drev* (src dest)
"Construct a list, moving elements of src to dest, including sub lists"
(cond
((null src) dest)
((listp (first src))
(drev* (rest src) (cons (drev* (first src) nil) dest))
)
(t (drev* (rest src) (cons (first src) dest)))
)
)
(defun rev* (lst)
"Takes a list and creates a mirror image of it"
(drev* lst nil)
)
(defun towers (discs start finish extra)
"Towers of Hanoi"
(cond
((= discs 1)
(princ "Move from ") (princ start)
(princ " to ") (princ finish) (terpri)
)
(t
(towers (- discs 1) start extra finish)
(towers 1 start finish extra)
(towers (- discs 1) extra finish start)
)
)
)