Advertisement
Guest User

Liaer

a guest
Apr 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.90 KB | None | 0 0
  1. ;gnu clisp 2.49
  2.  
  3. (defun factorial (a)
  4.   (cond ((= a 0) 1)
  5.         ((= a 1) 1)
  6.         ((= a 2) 2)
  7.         (t (* (factorial (- a 1)) a))
  8.   )                    
  9. )
  10.  
  11.  
  12. (defun fib (n)
  13.   (cond ((= n 0) 0)
  14.         ((= n 1) 1)
  15.         (t (+ (fib (- n 1)) (fib (- n 2))))
  16.   )
  17. )
  18.  
  19.  
  20. (defun fact2 (n1 n2)
  21.     (cond ((> n2 n1) nil)
  22.         ((= n1 (- n2 1)) n2)
  23.         ((= n1 n2) n2)
  24.         ((= n1 (+ n2 1)) (+ n2 1))
  25.         (t (* (fact2 (- n1 1) n2) n1))
  26.     )
  27. )
  28.  
  29. (defun acker (m n)
  30.   (cond ((< n 0) nil)
  31.         ((< m 0) nil)
  32.         ((= m 0) (+ 1 n))
  33.         ((= n 0) (acker (- m 1) 1))
  34.         (t (acker (- m 1) (acker m (- n 1))))
  35.   )    
  36. )
  37.  
  38. (print '----------------------------)
  39. (print (fact2 1 1))
  40. (print (fact2 -1 1))
  41. (print (fact2 6 2))
  42. (print (fact2 6 6))
  43. (print '----------------------------)
  44. (print (acker -1 5))
  45. (print (acker 1 1))
  46. (print (acker 0 4))
  47. (print (acker 3 3))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement