Skip to content

Instantly share code, notes, and snippets.

@rolisz
Created January 4, 2014 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rolisz/8253842 to your computer and use it in GitHub Desktop.
Save rolisz/8253842 to your computer and use it in GitHub Desktop.
Pregatire pentru examenul scris la PLF, LISP
(defun inserare(el l)
(cond
((null l) nil)
(t (mapcar (lambda (x) (cons el x)) l))
)
)
(defun permutare(l)
(cond
((null l) '(()))
(t (mapcan (lambda (x) (inserare x (permutare (elimina x l)))) l))
)
)
(defun elimina (el l)
(cond
((null l) nil)
((= el (car l)) (cdr l))
(t (cons (car l) (elimina el (cdr l))))
)
)
; l3 pb 13
(defun replace_cu_elem (el l l1)
(cond
((null l) nil)
(t (setq w(mapcar (lambda (x)
(cond
((and (atom x) (= x el)) l1)
((atom x) (list x))
(t (replace_cu_elem el x l1))
)
) l)) (print w)
;(setq r (append w))
(setq r (apply #'nconc w))
(print r)
w)
)
)
(defun concat(l &optional level)
(cond
((null l) nil)
((and level (listp (car l))) (append (list (concat (car l))) (concat (cdr l) t)))
((listp (car l)) (append (concat (car l) t) (concat (cdr l) level)))
(t (cons (car l) (concat (cdr l) level)))
)
)
(defun rep(el l l1)
(cond
((null l) nil)
((and (atom (car l)) (= el (car l))) (append l1 (rep el (cdr l) l1)))
((atom (car l)) (cons (car l) (rep el (cdr l) l1)))
(t (append (list (rep el (car l) l1)) (rep el (cdr l) l1)))
)
)
(defun rep2(el l l1)
(print 'start)
(print l)
(if (null l)
nil
(concat (mapcar #'(lambda (x)
(print (cond
((and (atom x) (= el x)) l1)
((atom x) (list x))
(t (list (rep2 el x l1)))
))
)
l
))
)
)
(defun dublare_n(l n &optional (i 1))
(cond
((null l) nil)
((= i n) (cons (car l) (cons (car l) (dublare_n (cdr l) n 1))))
(t (cons (car l) (dublare_n (cdr l) n (+ i 1))))
)
)
(defun numara_nenumeric_pare(l niv)
(if (eq (mod niv 2) 1)
(cond
((null l) 0)
((listp (car l)) (+ (numara_nenumeric_pare (car l) (+ niv 1)) (numara_nenumeric_pare (cdr l) niv)))
(t (numara_nenumeric_pare (cdr l) niv) )
)
(cond
((null l) 0)
((numberp (car l)) (numara_nenumeric_pare (cdr l) niv))
((atom (car l)) (+ 1 (numara_nenumeric_pare (cdr l) niv)))
(t (+ (numara_nenumeric_pare (car l) (+ niv 1)) (numara_nenumeric_pare (cdr l) niv)))
)
)
)
(defun nnpm(l niv)
(print l)
(cond
((listp l) (apply #'+ (mapcar #'(lambda (x) (nnpm x (+ 1 niv)))
l)))
((and (eq (mod niv 2) 1) (not (numberp l))) 1)
(t 0)
)
)
(defun ex3(l)
(cond
((atom l) 0)
(t (+ (apply #'+ (mapcar #'(lambda (x) (ex3 x)) l))
(mod (nnpm l 1) 2)
))
)
)
(defun elimin(l)
(cond
((and (numberp l) (minusp l)) nil)
((atom l) (list l))
(t (list (mapcan 'elimin l)))
)
)
(defun pozitie(l i)
(cond
((null l) nil)
((eq (mod i 2) 0) (print 'par) (print (car l)) (pozitie (cdr l) (+ i 1)))
(t (print 'impar) (print (car l)) (pozitie (cdr l) (+ i 1)))
)
)
(defun suma(l)
(cond
((null l) nil)
((numberp l) l)
((atom l) 0)
(t (apply #'+ (mapcar #'suma l)))
)
)
(defun arb_inloc(l s d)
(cond
((null l) nil)
((and (atom l) (eq l s)) d)
((atom l) l)
(t (mapcar #'(lambda (x) (arb_inloc x s d)) l))
)
)
(defun adancime_lista(l)
(cond
((null l) 0)
((atom l) 0)
(t (+ 1(apply #'max (mapcar #'adancime_lista l))))
)
)
(defun invers_subliste(l)
(cond
((null l) nil)
((atom l) l)
(t (invers (mapcar #'invers_subliste l)))
)
)
(defun invers(l &optional (col nil))
(cond
((null l) col)
(t (invers (cdr l) (cons (car l) col)))
)
)
(defun nr_nod(l k)
(cond
((null l) 0)
((and (atom l) (= k 0)) 1)
((atom l) 0)
(t (apply #'+ (mapcar #'(lambda (x) (nr_nod x (- k 1))) l)))
)
)
(defun sterge_toate(l e)
(cond
((null l) nil)
((and (atom l) (eq l e)) nil)
((atom l) (list l))
(t (list (mapcan #'(lambda (x) (sterge_toate x e)) l)))
)
)
(defun liniarize(l)
(cond
((null l) nil)
((atom l) (list l))
(t (mapcan #'liniarize l))
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment