Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun fact(n) ; Problema 1
- (cond ((zerop n) 1)
- ((equal n 1) 1)
- (t (* n (fact (- n 1))))
- )
- )
- (defun fibonacci(n) ; Problema 2
- (cond ((zerop n) 0)
- ((equal n 1) 1)
- (t (+ (fibonacci(- n 1)) (fibonacci(- n 2))))
- )
- )
- (defun my_member(x lst) ; Problema 3
- (cond ((null lst) nil)
- ((equal (car lst) x) t)
- (t (my_member x (cdr lst)))
- )
- )
- (defun trim-head (lst n) ; Problema 4
- (cond ((> n (length lst)) '(nil))
- ((null lst) '(nil))
- ((zerop n) lst)
- (t (trim-head (cdr lst) (- n 1)))
- )
- )
- (defun trim-tail (lst n) ; Problema 5
- (reverse (trim-head (reverse lst) n))
- )
- (defun count-atoms (lst) ; Problema 6
- (cond ((null lst) 0)
- (t (+ (cond ((atom (car lst)) 1)
- ((count-atoms (car lst))))
- (count-atoms (cdr lst))))
- )
- )
- (defun squash (lst) ; Problema 10
- (cond ((null lst) nil)
- ((atom lst) (list lst))
- (t (append (squash (car lst)) (squash (cdr lst))))
- )
- )
- (defun presentp (n lst) ; Problema 9
- (cond ((null lst) nil)
- ((cond ((atom (car lst)) (equal (car lst) n))
- ((presentp n (car lst)))))
- (t (presentp n (cdr lst)))
- )
- )
- (defun rev (lst a) ; Problema 8
- (cond ((null lst) a)
- (t (rev (cdr lst) (cons (car lst) a)))
- )
- )
- (defun my_reverse(lst) (rev lst nil))
- (defun inc (n) (+ n 1)) ; Problema 7
- (defun my_add(n1 n2 ac)
- (cond ((equal ac (+ n1 n2)) ac)
- (t (my_add n1 n2 (inc ac)))
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement