Advertisement
jovanovski

ВИ Лаб3

Mar 27th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.87 KB | None | 0 0
  1. ;Zad 1:
  2.  
  3. (defun stepe (n m)
  4.   (if (eq m 1)
  5.     n
  6.     (* n (stepe n (- m 1))))
  7. )
  8.  
  9. (stepe 4 2)
  10.  
  11.  
  12. ;Zad 2:
  13.  
  14. (defun suma (zbir dokj n)
  15.   (if (eq n dokj)
  16.     zbir
  17.     (suma (+ zbir (+ dokj 1)) (+ dokj 1) n))
  18. )
  19.  
  20. (suma 0 0 5)
  21.  
  22. ;Zad 3:
  23.  
  24. (defun grdasuma (zbir zbirs dokj n)
  25.   (if (eq (+ n 1) dokj)
  26.     zbir
  27.     (grdasuma (+ zbir (+ zbirs dokj )) (+ zbirs dokj) (+ dokj 1) n))
  28. )
  29.  
  30. (grdasuma 0 0 1 4)
  31.  
  32. ;Zad 4:
  33.  
  34. (defun nepbr (l)
  35.   (pomosna '() l)
  36.  
  37. )
  38.  
  39. (defun pomosna (noval l)
  40.   (if (null l)
  41.     noval
  42.   (if (= (mod (car l) 2) 1)
  43.    
  44.     (pomosna (append noval (list (car l))) (cdr l))
  45.    
  46.     (pomosna noval (cdr l))
  47.     )
  48.     )
  49.  
  50.  
  51.   )
  52.  
  53. (nepbr '(1 2 -3))
  54.  
  55. ;pusi k
  56.  
  57.  
  58. ;Zad 5:
  59.  
  60. (defun brpodlisti (l)
  61.   (pomosna 0 l)
  62.  
  63. )
  64.  
  65. (defun pomosna (brojac l)
  66.   (if (null l)
  67.     brojac
  68.   (if (listp (car l))
  69.     (pomosna (+ brojac 1) (cdr l))
  70.     (pomosna brojac (cdr l))
  71.    
  72.     )
  73.     )
  74.  
  75.  
  76.   )
  77.  
  78. (brpodlisti '(1 '(2) '(-3)))
  79.  
  80. ;Zad 6:
  81.  
  82. (defun br_atom (l)
  83.   (pomosna 0 l)
  84.  
  85. )
  86.  
  87. (defun pomosna (brojac l)
  88.   (if (null l)
  89.     brojac
  90.   (if (atom (car l))
  91.     (pomosna (+ brojac 1) (cdr l))
  92.     (pomosna (+ brojac (pomosna 0 (car l))) (cdr l))
  93.    
  94.     )
  95.     )
  96.  
  97.  
  98.   )
  99.  
  100. (br_atom '(a 4 (ana 9 m) 6 7))
  101.  
  102. ;Zad 7:
  103.  
  104. (defun br_atom (l)
  105.   (pomosna '() l)
  106.  
  107. )
  108.  
  109. (defun pomosna (noval l)
  110.   (if (null l)
  111.     noval
  112.   (cond
  113.     ((numberp (car l)) (pomosna (append noval (list (car l))) (cdr l)))
  114.     ((atom (car l)) (pomosna noval (cdr l)))
  115.     ((listp (car l)) (pomosna (append noval (pomosna noval (car l))) (cdr l)))
  116.    
  117.     )
  118.     )
  119.  
  120.  
  121.   )
  122.  
  123. (br_atom '(a (1 2) 4 c))
  124.  
  125. ;Mala 8ma Zad:
  126.  
  127. (defun otstraniN (l n)
  128.   (pomosna '() l n)
  129.  
  130. )
  131.  
  132. (defun pomosna (noval l n)
  133.   (if (= n 1)
  134.     (append noval (cdr l))
  135.   (pomosna (append noval (list (car l))) (cdr l) (- n 1))
  136.     )
  137.  
  138.  
  139.   )
  140.  
  141. (otstraniN '(1 2 3 4 5 6 7) 3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement