;;; Questao 1 (defun dist (peixe) (let ((x (first peixe)) (y (second peixe)) ) (sqrt (+ (* x x) (* y y))) ) ) (defun raio (peixes n) (first-n n (sort (mapcar #'dist peixes) #'<)) ) (defun first-n (n lista) (if (null lista) nil (or (nth (1- n) lista) (car (last lista)) ) ) ) ;;; Questao 2 (defun violacao (lista restricoes) (cond ((null restricoes) nil) ((viola lista (car restricoes)) (car restricoes)) (t (violacao lista (cdr restricoes))) ) ) (defun viola (lista restricao) (not (subset2 restricao lista)) ) (defun subset2 (restricao lista) (member (second restricao) (member (first restricao) lista) ) ) ;;; Questao 3 (defun net-value (mov conta t1 t2) "net value for an account in a transaction" (let ((md (first mov)) (mp (second mov)) (mt (third mov)) (mv (fourth mov)) ) (cond ((and (eql conta md) (eql conta mp) 0)) ((< mt t1) 0) ((> mt t2) 0) ((eql conta md) (- v)) ((eql conta mp) v) (t 0) ) ) ) (defun saldo (lista conta t1 t2) (apply #'+ (mapcar #'(lambda (x) (net x conta t1 t2)) lista)) ) ;;; Questao 4 (defun soma-impares (x) (if (>= x 1) (soma-aux 1 x) 0 ) ) (defun soma-aux (i x) (if (> i x) 0 (+ i (soma-aux (+ i 2) x)) ) )