Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1)
- (defun countatoms (lst)
- (if (equal lst nil)
- 0
- (if (atom (car lst))
- (+ 1 (countatoms (cdr lst)))
- (+ (countatoms (car lst)) (countatoms (cdr lst)))
- )
- )
- )
- Exemple:
- > (countatoms '(b c (d g) e))
- 5
- > (countatoms '(a (b (e f) c (g)) d))
- 7
- 2)
- (defun rot-left (lst n)
- (if (equal n 0)
- lst
- (rot-left (append (cdr lst) (list (car lst))) (- n 1))
- )
- )
- Exemple:
- > (rot-left '(1 2 3 4 5) 2)
- (3 4 5 1 2)
- > (rot-left '(a b (c) d) 3)
- (D A B (C))
- (defun rot-right (lst n)
- (if (equal n 0)
- lst
- (rot-right (append (last lst) (reverse (cdr (reverse lst)))) (- n 1))
- )
- )
- Exemple:
- > (rot-right '(a b (c) d) 3)
- (B (C) D A)
- > (rot-right '(1 2 3 4 5) 2)
- (4 5 1 2 3)
- 3)
- (defun fara_dubluri (lst)
- (if (null lst)
- '()
- (if (member (car lst) (cdr lst))
- (fara_dubluri (cdr lst))
- (append (list(car lst)) (fara_dubluri (cdr lst)))
- )
- ))
- Exemple:
- > (fara_dubluri '(1 2 2 3 4 5 6 4 4))
- (1 2 3 5 6 4)
- > (fara_dubluri '(5 2 1 2 2 2 5 5 1))
- (2 5 1)
- 4)
- (defun presentp (lst atm)
- (cond
- ((null lst) nil)
- ((listp (car lst)) (or (presentp (car lst) atm) (presentp (cdr lst) atm)))
- ((atom (car lst)) (if (equal (car lst) atm)
- T
- (presentp (cdr lst) atm)
- ))
- )
- )
- Exemple:
- > (presentp '(a b c (d f) g) 'f)
- T
- > (presentp '(a b c (d f) w) 'g)
- NIL
- 5)
- (defun cifre (n)
- (if
- (equal n 0)
- '()
- (append (cifre (floor (/ n 10))) (list(rem n 10)))
- )
- )
- Exemple:
- > (cifre 6326761)
- (6 3 2 6 7 6 1)
- > (cifre 36121)
- (3 6 1 2 1)
- 6)
- (defun pozpar (lst)
- (
- do
- (
- (l lst (cddr l))
- (x '() (append x (list (car l))))
- )
- ((null l) x)
- )
- )
- Exemple:
- > (pozpar '(1 2 3 4 5 6 7))
- (1 3 5 7)
- > (pozpar '(a b (c d) s ((x))))
- (A (C D) ((X)))
- 7)
- (defun cmmdc (a b)
- (
- do
- (
- (x a (if (> x y) (- x y) x))
- (y b (if (> y x) (- y x) y))
- )
- ((equal x y) x)
- )
- )
- Exemple:
- > (cmmdc 24 18)
- 6
- > (cmmdc 108 48)
- 12
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement