Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Problema [1]
- (defun suma(l)
- (apply '+ (remove-if-not '(lambda (x) (evenp (position x l))) l))
- )
- ;EXEMPLU
- ;(suma '(1 2 3 4 5))
- ;9
- ;> (suma '(0 1 0 1 0 1))
- ;0
- ;>
- ;____________________________________________________________________
- ;Problema [2]
- ;(rot-left '(a b c) 1)
- ;(B C A)
- ;> (rot-left '(a b c) 2)
- ;(C A B)
- ;>
- (defun rot-right (lista n)
- (cond
- ((= n 0) lista)
- (t (rot-right (append (last lista) (reverse (cdr (reverse lista)))) (- n 1)))
- )
- )
- ;(rot-right '(a b c) 1)
- ;(C A B)
- ;> (rot-right '(a b c) 2)
- ;(B C A)
- ;>
- ;____________________________________________________________________
- ;Problema [3]
- (defun aparitii (lista x)
- (setq count 0)
- (car (last (mapcar '(lambda (i) (if (= i x) (setq count (+ count 1)))) lista)))
- )
- ;EXEMPLU:
- ;>(lungimi '((b c) (d e f)) '())
- ;(2 3)
- ;> (lungimi '((b c) d e (f) g (h i j)) '())
- ;(2 1 3)
- ;>
- ;> (lungimi '(a b c) '())
- ;NIL
- ;____________________________________________________________________
- ;Problema [4]
- ;(presentp '(a (b c)) 'b)
- ;T
- ;> (presentp '(a (b c) (d e f) (g)) 'f)
- ;T
- ;>
- ;____________________________________________________________________
- ;Problema [5]
- (defun cifre (x lista)
- (cond
- ((= x 0) lista)
- (t (cifre (floor (/ x 10)) (append (list (mod x 10)) lista)))
- )
- )
- ;> (cifre 3548 '())
- ;(3 5 4 8)
- ;____________________________________________________________________
- ;Problema [6]
- (defun pozpar (lista)
- (do ( (i 1 (+ i 1)) (l lista (cdr l)) (listai '() ) )
- ((null l) listai)
- (if (not (= (mod i 2) 0)) (setq listai (append listai (list (car l)))))
- )
- )
- ;> (pozpar '(1 2 3 4 5 6 7))
- ;(1 3 5 7)
- ;____________________________________________________________________
- ;Problema [7]
- (defun cmmdc (x y)
- (do ( (a x) (b y) )
- ((= a b) a)
- (if (> a b) (setq a (- a b)) (setq b (- b a)))
- )
- )
- ;> (cmmdc 25 5)
- ;5
- ;> (cmmdc 3 27)
- ;3
- ;____________________________________________________________________
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement