Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.79 KB | None | 0 0
  1. 1)
  2. (defun countatoms (lst)
  3. (if (equal lst nil)
  4. 0
  5. (if (atom (car lst))
  6. (+ 1 (countatoms (cdr lst)))
  7. (+ (countatoms (car lst)) (countatoms (cdr lst)))
  8. )
  9. )
  10. )
  11. Exemple:
  12. > (countatoms '(b c (d g) e))
  13. 5
  14. > (countatoms '(a (b (e f) c (g)) d))
  15. 7
  16.  
  17. 2)
  18. (defun rot-left (lst n)
  19. (if (equal n 0)
  20. lst
  21. (rot-left (append (cdr lst) (list (car lst))) (- n 1))
  22. )
  23. )
  24. Exemple:
  25. > (rot-left '(1 2 3 4 5) 2)
  26. (3 4 5 1 2)
  27. > (rot-left '(a b (c) d) 3)
  28. (D A B (C))
  29.  
  30. (defun rot-right (lst n)
  31. (if (equal n 0)
  32. lst
  33. (rot-right (append (last lst) (reverse (cdr (reverse lst)))) (- n 1))
  34. )
  35. )
  36. Exemple:
  37. > (rot-right '(a b (c) d) 3)
  38. (B (C) D A)
  39. > (rot-right '(1 2 3 4 5) 2)
  40. (4 5 1 2 3)
  41.  
  42. 3)
  43. (defun fara_dubluri (lst)
  44. (if (null lst)
  45. '()
  46. (if (member (car lst) (cdr lst))
  47. (fara_dubluri (cdr lst))
  48. (append (list(car lst)) (fara_dubluri (cdr lst)))
  49. )
  50. ))
  51. Exemple:
  52. > (fara_dubluri '(1 2 2 3 4 5 6 4 4))
  53. (1 2 3 5 6 4)
  54. > (fara_dubluri '(5 2 1 2 2 2 5 5 1))
  55. (2 5 1)
  56.  
  57. 4)
  58. (defun presentp (lst atm)
  59. (cond
  60. ((null lst) nil)
  61. ((listp (car lst)) (or (presentp (car lst) atm) (presentp (cdr lst) atm)))
  62. ((atom (car lst)) (if (equal (car lst) atm)
  63. T
  64. (presentp (cdr lst) atm)
  65. ))
  66. )
  67. )
  68. Exemple:
  69. > (presentp '(a b c (d f) g) 'f)
  70. T
  71. > (presentp '(a b c (d f) w) 'g)
  72. NIL
  73.  
  74. 5)
  75. (defun cifre (n)
  76. (if
  77. (equal n 0)
  78. '()
  79. (append (cifre (floor (/ n 10))) (list(rem n 10)))
  80. )
  81. )
  82. Exemple:
  83. > (cifre 6326761)
  84. (6 3 2 6 7 6 1)
  85. > (cifre 36121)
  86. (3 6 1 2 1)
  87.  
  88. 6)
  89. (defun pozpar (lst)
  90. (
  91. do
  92. (
  93. (l lst (cddr l))
  94. (x '() (append x (list (car l))))
  95. )
  96. ((null l) x)
  97. )
  98. )
  99. Exemple:
  100. > (pozpar '(1 2 3 4 5 6 7))
  101. (1 3 5 7)
  102. > (pozpar '(a b (c d) s ((x))))
  103. (A (C D) ((X)))
  104.  
  105. 7)
  106. (defun cmmdc (a b)
  107. (
  108. do
  109. (
  110. (x a (if (> x y) (- x y) x))
  111. (y b (if (> y x) (- y x) y))
  112. )
  113. ((equal x y) x)
  114. )
  115. )
  116. Exemple:
  117. > (cmmdc 24 18)
  118. 6
  119. > (cmmdc 108 48)
  120. 12
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement