Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define (maptree fun tree)
- (if (empty? tree) '()
- (list (fun (car tree)) (maptree fun (cadr tree)) (maptree fun (caddr tree)))))
- (define (leaf? tree)
- (and (empty? (cadr tree)) (empty? (caddr tree))))
- (define (remove tree)
- (if (empty? tree) '()
- (cond
- ((and (empty? (cadr tree)) (empty? (caddr tree))) (list (car tree) (remove (cadr tree)) (remove (caddr tree))))
- ((empty? (caddr tree)) (list (caadr tree) (remove (cadadr tree)) (remove (car (cddadr tree)))))
- ((empty? (cadr tree)) (list (caaddr tree) (remove (car (cdaddr tree))) (remove (cadr (cdaddr tree)))) )
- (else (list (car tree) (remove (cadr tree)) (remove (caddr tree)))) )))
- (define (fun tree)
- (if (leaf? tree)
- #t
- (and (not (or (null? (cadr tree)) (null? (caddr tree)))) (fun (cadr tree)) (fun (caddr tree)))))
- (define (MAIN tree)
- (define (comp tree1)
- (if (fun tree1) tree1
- (comp (remove tree1))))
- (if (empty? tree) null
- (if (and (not (empty? (cadr tree))) (empty? (caddr tree))) (list (car tree) (comp(cadr tree)) null)
- (if (and (empty? (cadr tree)) (not (empty? (caddr tree)))) (list (car tree) null (comp (caddr tree)))
- (comp tree)))))
- (define (sort-vkl lst)
- (cond
- [(empty? lst) empty]
- [(cons? lst) (insert (car lst) (sort-vkl (cdr lst)))]))
- (define (SumDig k) ;считает сумму цифр
- (define (computing n res)
- (if (= 0 (quotient n 10)) (+ n res)
- (computing (quotient n 10) (+ res (remainder n 10)))))
- (computing k 0))
- (define (insert n lst)
- (cond
- [(empty? lst) (list n)]
- [else (cond
- [(> (SumDig n) (SumDig (car lst))) (cons n lst)] ;по сумме цифр смотрит, куда вставить текущий вариант
- [(<= (SumDig n) (SumDig (car lst))) (cons (car lst) (insert n (cdr lst)))])]))
Add Comment
Please, Sign In to add comment