jueves, 30 de agosto de 2012
jueves, 23 de agosto de 2012
martes, 21 de agosto de 2012
jueves, 16 de agosto de 2012
miércoles, 15 de agosto de 2012
EJERCICIOS LISP
DESCRIPCION
CREAR UNA FUNCION EN
DONDE DE COMO RESULTADO EL ULTIMO
ELEMENTO DE UNA LISTA
SOLUCION
( defun ultimo (y) (if (cdr y) ( ultimo (cdr y) ) y ) )
DESCRIPCION
DEVUELVE EL PRIMER Y ULTIMO ELEMENTO DE UNA LISTA
SOLUCION
(defun ejer1 (lista) (append (list(car lista)) (ultimo
lista) ) )
( defun ultimo (y) (if (cdr y) ( ultimo (cdr y) ) y ) )
DESCRIPCION
SUMATORIA DE LOS ELEMENTOS DE UNA LISTA
SOLUCION
(DEFUN sumatoria (N)
(if (cdr n)
(+ (car n)
(sumatoria (cdr n)) )
(car n)
) )
(sumatoria '(1 2 3 4 5 6 7 8 9))
Descripción
SUMA DE MATRICES
Solución
(defun sumaprimer (x y) (+ (car x) (car y)) )
(defun sumacol (x1 y1) (if (cdr x1)
(cons(sumaprimer x1 y1) (sumacol (cdr x1)(cdr y1)) )
(list(sumaprimer x1 y1))
)
)
(defun sumamat (x y) (append (list(sumacol (car x) (car y)))
(if (cdr (cdr x)) (sumamat (cdr x) (cdr y))
(list (sumacol (car (cdr x)) (car (cdr y))))
)
)
)
(sumamat '((1 3)(4 5)(3 5)) '((6 7)(8 9)(4 3)))
Descripción
Defina una función “nesimo” que dado un entero “n” y una lista “L” retorne una nueva lista eliminando el n-ésimo elemento de la lista.
Solución
$ (nesimo 3 '(1 -3 5 4 9))
(1 -3 4 9)
(defun nesimo (n lista)
( IF (NOT (NULl lista ))
(setq n (- n 1))
)
(IF (NOT (NULL lista ))
(if (eq n 0)
(append (cdr lista)
)
(append (list(car lista)) (nesimo n (cdr lista))
)
)
)
)
(nesimo 2 '(2 3 4))
Descripción
Ingresar el nombre del estudiante y un limite de notas en una lista y mostar si aprueba o no
Solución
(DEFUN sumatoria (N) (if (cdr n) (+ (car n) (sumatoria (cdr n)) )
(car n)
)
)
(defun promedio (l) (/ (sumatoria (car(cdr l))) (length (car(cdr l))))
)
(defun aprueba (l)( if (< (promedio (car l)) 7) 'Repr 'Aprb) )
(defun cargarlista (l)
(list (caar l) (promedio (car l)) (aprueba l) )
)
(defun evalua (l)
(append (list (cargarlista l))
(if (cdr (cdr l))
(evalua (cdr l))
(append(list (cargarlista (cdr l))))
)
)
)
Suscribirse a:
Entradas (Atom)