-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2009-01-12.lisp
58 lines (52 loc) · 1.27 KB
/
2009-01-12.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
49
50
51
52
53
54
55
56
57
58
(defun replace (lst oldv newv)
"Replace the old value in the list with the new value"
(cond
((null lst) nil)
((eq (car lst) oldv)
(cons newv (replace (cdr lst) oldv newv))
)
(t (cons (car lst) (replace (cdr lst) oldv newv)))
)
)
(defun replace* (lst oldv newv)
"Replace old value with new value in all levels of the list"
(cond
((null lst) nil)
((eq (car lst) oldv)
(cons newv (replace* (cdr lst) oldv newv))
)
((listp (car lst))
(cons (replace* (car lst) oldv newv) (replace* (cdr lst) oldv newv))
)
(t (cons (car lst) (replace* (cdr lst) oldv newv)))
)
)
(defun reverse (lst)
"Create separate list, move from one list to another."
(dreverse lst nil)
)
(defun dreverse (src dest)
"Move element from src to dest"
(cond
((null src) dest)
(t (dreverse (car src) dest))
)
)
(defun mirror (lst)
"Documentation for mirror."
())
(defun towers (discs start finish extra)
"Towers of Hanoi"
(cond
((= discs 1) (princ "Move from ") (princ ) (princ " to ") (princ ) (terpri))
(t
(towers (- discs 1) start finish extra)
(towers 1 start finish extra)
(towers (- discs 1) start finish extra)
)
)
)
; Move from a to b
; Move from a to c
; Move from b to c
; Move from a to b