Advertisement
Teammasik

laba4_paradigmas

Apr 27th, 2023
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.88 KB | None | 0 0
  1. ;1
  2. (defun summa (m n) (cond
  3.                        ((< n 0) 0)
  4.                        ((> m n) 0)
  5.                        ((evenp n) ( + n (summa m (- n 2))))
  6.                        (t (summa m (- n 1)))
  7.                    )
  8.     )
  9. ;(print (summa 2 6))
  10.  
  11. ;2
  12. (setq lst '(k b c))
  13.  
  14. (defun counts (w)
  15.   (cond ((null w) 0)
  16.         ((numberp (car w)) (counts (cdr w)))
  17.         ((listp (car w)) (+ (counts (car w)) (counts (cdr w))))
  18.         ((symbolp (car w)) (+ 1 (counts (cdr w))))
  19.       )
  20.     )
  21.  
  22. (print(counts lst))
  23.  
  24. ;(print(symbolp (caddr lst)))
  25.  
  26.  
  27. (print(counts '(a (c 5 (d s s((s))) e)g)))
  28.  
  29. ;3
  30. (defun f(n)
  31.     (cond ((= n 0) 1)
  32.     ((= n 1) 2)
  33.     (t (-(* 2 (f (- n 1)))  (f(- n 2))))
  34.         ) )
  35.  
  36. ;(print (f 4))
  37.  
  38. ;4
  39. (defun create (a n)
  40.     (cond ((= n 0) nil)
  41.     (t(cons (cons a nil) (create a (- n 1))))
  42.         )
  43.             )
  44.    
  45.  
  46. ;(print(create 2 4))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement