Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define % remainder)
- (define // quotient)
- (define (prost n)
- (define kor (sqrt n))
- (define (iter n i)
- (if (> i kor) #t
- (if (= (% n i) 0) #f
- (iter n (+ i 1)))))
- (if (= n 1) #f
- (iter n 2)))
- (define (oldfirst x)
- (define (itern x i n)
- (if (> (% x i) 0) (cons (cons i n) x)
- (itern (/ x i) i (+ 1 n))))
- (define (iter x i s )
- (if (= x 1) s
- (if (> (cdr (car (itern x i 0))) 0) (iter (cdr (itern x i 0)) (+ i 1) (cons (car (itern x i 0)) s))
- (iter x (+ 1 i) s))))
- (if (prost x) (list (cons x 1))
- (reverse (iter x 2 null))))
- (define (oldfive a s)
- (define (obeznul x)
- (if (> (% x 10) 0) x
- (obeznul (// x 10))))
- (define (beznul a e)
- (if (empty? a) e
- (beznul (cdr a) (cons (obeznul (car a)) e))))
- (define (itern x n)
- (if (= x 0) n
- (itern (// x 10) (+ (* n 10) (% x 10)))))
- (define (iter a s)
- (if (and (empty? a) (empty? s)) #t (if (or (empty? a) (empty? s)) #f
- (if (= (car a) (itern (car s) 0)) (iter (cdr a) (cdr s))
- #f))))
- (define perv (reverse (beznul a null)))
- (define vtor (reverse (beznul s null)))
- (or (iter perv (reverse vtor)) (iter vtor (reverse perv))))
- (define (first s)
- (define (itern s x ns)
- (if (empty? s) ns
- (if (= x (car s)) (itern (cdr s) x ns)
- (itern (cdr s) x (cons (car s) ns)))))
- (define (iter s i)
- (if (empty? s) i
- (iter (itern s (car s) null) (+ 1 i))))
- (iter s 0))
- (define (second s)
- (define (itern s x ns para)
- (if (empty? s) (cons ns para)
- (if (= x (car s)) (itern (cdr s) x ns (cons x (+ (cdr para) 1)))
- (itern (cdr s) x (cons (car s) ns) para))))
- (define (iter s otv)
- (if (empty? s) otv
- (iter (car (itern s (car s) null (cons (car s) 0))) (cons (cdr (itern s (car s) null (cons (car s) 0))) otv))))
- (reverse (iter s null)))
- (define (fib n)
- (define (iter n a b i)
- (if (= n i) (+ a b)
- (iter n (+ a b) a (+ 1 i))))
- (iter n 0 1 0))
- (define (fib? n)
- (define (iter n i)
- (if (= (fib i) n) #t
- (if (> (fib i) n) #f
- (iter n (+ 1 i)))))
- (iter n 0))
- (define (third s)
- (define (iter s ns)
- (if (empty? s) ns
- (if (fib? (car s)) (iter (cdr s) (cons (car s) ns))
- (iter (cdr s) ns))))
- (first (iter s null)))
- (define (NOD x y)
- (define (iter x y)
- (if (= x y) x
- (if (> x y) (iter (- x y) y)
- (iter x (- y x)))))
- (iter x y))
- (define (fourth a s)
- (define (iter a s ns)
- (if (and (empty? s) (empty? a)) ns
- (if (or (empty? s) (empty? a)) ns
- (if (= (NOD (car a) (car s)) 1) (iter (cdr a) (cdr s) (cons (cons (car a) (car s)) ns))
- (iter (cdr a) (cdr s) ns)))))
- (reverse (iter a s null)))
- (define (five s)
- (define (iter s ns ok)
- (if (empty? s) ns
- (iter (cdr s) (cons (reverse ok) ns) (cons (car s) ok))))
- (append (reverse (iter (cdr s) null (list (car s)))) (list s)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement