Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;1 c прошлой лабы
- (define (splitting lst n r1 r2 r3 l1 l2 l3)
- (if (and (= n l1) (= n l2) (= n l3)) (list r1 r2 r3)
- ( cond((and (<(length r1)n) (= 0 (remainder (car lst) 3)))
- (splitting (cdr lst) n (cons (car lst) r1) r2 r3 (+ 1 l1) l2 l3))
- ((and (< (length r2) n) (= 1 (remainder (car lst) 3)))
- (splitting (cdr lst) n r1 (cons (car lst) r2) r3 l1 (+ 1 l2) l3))
- ( (and (<(length r3) n) (= 2 (remainder (car lst) 3)))
- (splitting (cdr lst) n r1 r2 (cons (car lst) r3) l1 l2 (+ 1 l3)))
- (else (splitting (cdr lst) n r1 r2 r3 l1 l2 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 задача c прошлой
- (define (Maxtree tree)
- (if (empty? tree) -999999000000
- (max (car tree) ( max (Maxtree (cadr tree)) (Maxtree (caddr tree))))))
- (define (CountMax tree)
- (define Max (Maxtree tree))
- (define (FunctionMax tree1 )
- (if (empty? tree1) 0
- (+ (if (= (car tree1) Max) 1 0)
- (FunctionMax (cadr tree1)) (FunctionMax (caddr tree1)))))
- (FunctionMax tree))
- ;5 задача с прошлой
- (define (KidsTree tree)
- (if (empty? tree) #t
- (cond ((or (and (empty? (cadr tree)) (not (empty? (caddr tree)))) (and (not (empty? (cadr tree))) (empty? (caddr tree))))#f )
- ((and (empty? (cadr tree)) (empty? (caddr tree))) #t)
- (else (and (KidsTree (cadr tree)) (KidsTree (caddr tree)))) )))
- ; 3 pflfxf
- (define (LeftTree tree)
- (define (lefttree tree )
- (if (empty? tree) 0
- (+ (if (not (empty? (cadr tree))) 1 0)
- (lefttree (cadr tree)) (lefttree (caddr tree)))))
- (lefttree tree ))
- ;4 pflfxf
- (define (Minlist tree)
- (if (empty? tree) +inf.0
- (if (and (empty? (cadr tree)) (empty? (caddr tree))) (car tree)
- (min (Minlist (cadr tree) (Minlist (caddr tree)))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement