Advertisement
Guest User

LegkiyLoot

a guest
Nov 14th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. (define % remainder)
  2. (define // quotient)
  3.  
  4. (define (prost n)
  5. (define kor (sqrt n))
  6. (define (iter n i)
  7. (if (> i kor) #t
  8. (if (= (% n i) 0) #f
  9. (iter n (+ i 1)))))
  10. (if (= n 1) #f
  11. (iter n 2)))
  12.  
  13. (define (oldfirst x)
  14. (define (itern x i n)
  15. (if (> (% x i) 0) (cons (cons i n) x)
  16. (itern (/ x i) i (+ 1 n))))
  17. (define (iter x i s )
  18. (if (= x 1) s
  19. (if (> (cdr (car (itern x i 0))) 0) (iter (cdr (itern x i 0)) (+ i 1) (cons (car (itern x i 0)) s))
  20. (iter x (+ 1 i) s))))
  21. (if (prost x) (list (cons x 1))
  22. (reverse (iter x 2 null))))
  23.  
  24.  
  25. (define (oldfive a s)
  26. (define (obeznul x)
  27. (if (> (% x 10) 0) x
  28. (obeznul (// x 10))))
  29. (define (beznul a e)
  30. (if (empty? a) e
  31. (beznul (cdr a) (cons (obeznul (car a)) e))))
  32. (define (itern x n)
  33. (if (= x 0) n
  34. (itern (// x 10) (+ (* n 10) (% x 10)))))
  35. (define (iter a s)
  36. (if (and (empty? a) (empty? s)) #t (if (or (empty? a) (empty? s)) #f
  37. (if (= (car a) (itern (car s) 0)) (iter (cdr a) (cdr s))
  38. #f))))
  39. (define perv (reverse (beznul a null)))
  40. (define vtor (reverse (beznul s null)))
  41. (or (iter perv (reverse vtor)) (iter vtor (reverse perv))))
  42.  
  43.  
  44.  
  45. (define (first s)
  46. (define (itern s x ns)
  47. (if (empty? s) ns
  48. (if (= x (car s)) (itern (cdr s) x ns)
  49. (itern (cdr s) x (cons (car s) ns)))))
  50. (define (iter s i)
  51. (if (empty? s) i
  52. (iter (itern s (car s) null) (+ 1 i))))
  53. (iter s 0))
  54.  
  55. (define (second s)
  56. (define (itern s x ns para)
  57. (if (empty? s) (cons ns para)
  58. (if (= x (car s)) (itern (cdr s) x ns (cons x (+ (cdr para) 1)))
  59. (itern (cdr s) x (cons (car s) ns) para))))
  60. (define (iter s otv)
  61. (if (empty? s) otv
  62. (iter (car (itern s (car s) null (cons (car s) 0))) (cons (cdr (itern s (car s) null (cons (car s) 0))) otv))))
  63. (reverse (iter s null)))
  64.  
  65. (define (fib n)
  66. (define (iter n a b i)
  67. (if (= n i) (+ a b)
  68. (iter n (+ a b) a (+ 1 i))))
  69. (iter n 0 1 0))
  70.  
  71. (define (fib? n)
  72. (define (iter n i)
  73. (if (= (fib i) n) #t
  74. (if (> (fib i) n) #f
  75. (iter n (+ 1 i)))))
  76. (iter n 0))
  77.  
  78. (define (third s)
  79. (define (iter s ns)
  80. (if (empty? s) ns
  81. (if (fib? (car s)) (iter (cdr s) (cons (car s) ns))
  82. (iter (cdr s) ns))))
  83. (first (iter s null)))
  84.  
  85. (define (NOD x y)
  86. (define (iter x y)
  87. (if (= x y) x
  88. (if (> x y) (iter (- x y) y)
  89. (iter x (- y x)))))
  90. (iter x y))
  91.  
  92. (define (fourth a s)
  93. (define (iter a s ns)
  94. (if (and (empty? s) (empty? a)) ns
  95. (if (or (empty? s) (empty? a)) ns
  96. (if (= (NOD (car a) (car s)) 1) (iter (cdr a) (cdr s) (cons (cons (car a) (car s)) ns))
  97. (iter (cdr a) (cdr s) ns)))))
  98. (reverse (iter a s null)))
  99.  
  100. (define (five s)
  101. (define (iter s ns ok)
  102. (if (empty? s) ns
  103. (iter (cdr s) (cons (reverse ok) ns) (cons (car s) ok))))
  104. (append (reverse (iter (cdr s) null (list (car s)))) (list s)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement