RESOLUCION DE LA PRACTICA CALIFICADA Nº1

PREGUNTA 01

Eliminar la lista L1 de la lista L2.

L1 = (1 2)

L2=   (1 2 3 4 ( 5 6) (1 2) )

Solución:

CL-USER 32 : 6 > setq l1 '(5 6)

(5 6)

CL-USER 32 : 7 > seqt l2 '(1 2 3 4 (5 6) 1 2)

CL-USER 32 : 8 >

(defun a (l1 l2 l3)

(if (listp (car l2)) (if (equal (car l2) l1) (setq l3 (append l3 (list(cdr l2))))())

(progn (setq l3 (append l3 (list(car l2)))) (a l1 (cdr l2) l3))))

A

CL-USER 33 : 8 > a l1 l2 l3

(1 2 3 4 (1 2))

CL-USER 33 : 8 > a l1 l2 l3

(1 2 3 4 (1 2))

PREGUNTA 02

Generar un algoritmo recursivo para_

Sm(x) = x+ x/2+ x/4+ x/8 + …+x/2x

Y calcular

Sm(5)

Sm (2)

(defun sm(x)

(if(eq x 0) 0 (+ x (* x (sumrecursiva x)))))

(defun sumrecursiva(x)

(if (eq x 1) 0.5 (+ (/ 1 (expt 2 x)) (sumrecursiva (- x 1)))))

sm 5

9.84375

sm 2

PREGUNTA 03

RemPenult  L1 L2

(1 2 3 4 ( a b c) (1 2) )

(defun el (l1 l2 p c)

(if (null l2) nil

(if (= p c)

(append (list l1) (el l1 (cdr l2) p (+ c 1)))

(append (list (car l2) )  (el l1 (cdr l2) p (+ c 1)))

)

))

( defun RemPenult ( l1 l2)

( el l1 l2 (- ( length l2) 2 ) 0 )  )