sábado, 16 de janeiro de 2021

Exemplo Lisp

 (defun soma (a b c)

  (+ a b c))


(defun quadrado(a)

  (* a a))


(defun tamanho(lst)

  (if (null lst)

    0

    (+1 (tamanho (cdr lst)))))


(defun enesimo(lst n)

  (if (not (null lst))

      (if (= l)

          (car lst)

          (enesimo (cdr lst) (-n 1)))))


(defun inverter (lst)

  (if (not (null lst))

      (append (inverter (cdr lst)) (list (car lst)))))


(defun membro(e lst)

(if (not (null lst))

(or (= e (car lst)) (membro e (cdr lst)))))

(defun soma (a b c)

  (+ a b c))



(defun quadrado (a)

  (* a a))

 



(defun media (a b)

  (/ (+ a b) 2))



(defun fat (n)

  (if (= n 0)

      1

      (* n (fat (- n 1)))))



(defun tamanho (lst)

  (if (null lst)

      0

      (+ 1 (tamanho (cdr lst)))))


(defun enesimo (lst n)

  (if (not (null lst))

      (if (= n 1)

          (car lst)

          (enesimo (cdr lst) (- n 1)))))



(defun inverter (lst)

  (if  (not (null lst))

       (append (inverter (cdr lst)) (list (car lst)))))



(defun membro (e lst)

  (if (not (null lst))

      (or (equal e (car lst)) (membro e (cdr lst)))))



(defun oco (a lst)

  (if (null lst)

      0

      (if (equal a (car lst))

          (+ 1 (oco a (cdr lst)))

          (oco a (cdr lst)))))



(defun mult (e lst)

  (if (not (null lst))

      (cons (* e (car lst)) (mult e (cdr lst)))))



(defun conc (lst1 lst2)

  (if (null lst1)

      lst2

      (cons (car lst1) (conc (cdr lst1) lst2))))


(defun deletar (a lst)

  (if (not (null lst))

      (if  (eql a (car lst))

           (deletar a (cdr lst))

           (cons (car lst) (deletar a (cdr lst))))))

 


(defun tirar_ult (lst)

  (if (not (null lst))

      (if  (not (null (cdr lst)))

           (cons (car lst) (tirar_ult (cdr lst))))))

           

(defun ultimo (lst)

  (if (not (null lst))

      (if (= 1 (tamanho lst))

          (car lst)

          (ultimo (cdr lst)))))


(defun palindromo2 (lst)

  (equal lst (inverter lst)))



(defun palindromo (lst)

  (if (not (null lst))

      (or (= 1 (tamanho lst))

          (and (= 2 (tamanho lst))

               (equal (car lst) (cadr lst)))

          (and (equal (car lst) (ultimo lst))

               (palindromo (tirar_ult (cdr lst)))))))


Um comentário:

  1. How to win in slot machines - Dr.MCD
    How to win in slot machines 울산광역 출장안마 The most common 전라남도 출장샵 slot machine 군산 출장샵 is called the 5-reel slot. For this slot 오산 출장샵 machine, you'll simply hold

    ResponderExcluir

Exercícios Preparação de soluções Ácidas - Resolução

 Exercícios Preparação de soluções Ácidas - Resolução NAOH 0,5 Mol/L HCL 0,5 Mol/L NaCL 0,1Mol/L Resolução: