Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;делит списки по 0 1 2
- (define (splitting lst n r1 r2 r3 l1 l2 l3)
- (if (and (= n l1) (= n l2) (= n l3)) (list r1 r2 r3)
- ( cond ( (= 0 (remainder (car lst) 3)) (splitting (cdr lst) n (cons (car lst) r1) r2 r3 (+ 1 l1) l2 l3))
- ( (= 1 (remainder (car lst) 3)) (splitting (cdr lst) n r1 (cons (car lst) r2) r3 l1 (+ 1 l2) l3))
- ( (= 2 (remainder (car lst) 3)) (splitting (cdr lst) n r1 r2 (cons (car lst) r3) l1 l2 (+ 1 l3))))))
- (define (main lst N)
- (define (threelist lst res)
- (if (empty? (car lst)) res
- (threelist (list(cdar lst) (cdadr lst) (cdaddr lst)) (cons (list(caar lst) (caadr lst) (caaddr lst)) res))))
- (threelist (splitting lst N '() '() '() 0 0 0) '()))
- ; 3 task
- (define (treelist tree)
- (if (empty? tree) '()
- (append (treelist (cadr tree)) (cons (car tree) (treelist (caddr tree))))))
- (define (Maxtree lst)
- (define (searchmax lst mx n)
- (if (empty? lst) n
- (cond ((< (car lst) mx) (searchmax (cdr lst) mx n))
- ((= (car lst) mx) (searchmax ( cdr lst) mx (+ 1 n)))
- ((> (car lst) mx) (searchmax (cdr lst)(car lst) (= 1 n))))))
- (searchmax (treelist lst)(car(treelist lst)) 0 ))
- ; 4 task
- (define (tree-list tree)
- (if (empty? tree) 0
- (+ ( if (and (empty? ( cadr tree)) (empty? (caddr tree))) 1 0)
- (tree-list (cadr tree)) (tree-list (caddr tree)))))
- ;5 задача
- (define (Twochildren tree)
- (define (parent tree)
- (if (empty? tree) 0
- (let ((left (parent (cadr tree)))
- (right (parent (caddr tree))))
- (if (or (not left)
- (not right)) #f
- (if (> (abs (- right left)) 0) #f
- (+ (max left right) 1))))))
- (number? (parent tree)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement