Skip to content

Commit 75690b4

Browse files
committed
adding more snippets (revers, fibonachi, bin-tree)
1 parent 474c7e2 commit 75690b4

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

bin-tree-sub-tree.lisp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(defun bin-tree-subtree (tree path)
2+
(if (and (> (length path) 0) (consp tree))
3+
(if (equal (subseq path 0 1) "L")
4+
(bin-tree-subtree (car tree) (subseq path 1 (length path)))
5+
(bin-tree-subtree (cdr tree) (subseq path 1 (length path)))
6+
)
7+
tree
8+
)
9+
)
10+
11+
(bin-tree-subtree '((1 . 2) . (3 . 4)) "LR")

fib.lisp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
(defun fib (x)
2+
(
3+
if (integerp x)
4+
(
5+
if (<= x 0)
6+
0
7+
(if (< x 2)
8+
1
9+
(+
10+
(fib (- x 1))
11+
(fib (- x 2))
12+
)
13+
)
14+
)
15+
-1
16+
)
17+
)

reverse.lisp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(defun myreverse (mylist)
2+
(
3+
if (true-listp mylist)
4+
(
5+
if (> (length mylist) 0)
6+
(append (myreverse (cdr mylist)) (list (car mylist)))
7+
'()
8+
)
9+
-1
10+
)
11+
)

0 commit comments

Comments
 (0)