Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define (Sol1 func tree)
- (if (empty? tree) '()
- (list (func (car tree)) (Sol1 func (cadr tree)) (Sol1 func (caddr tree)))))
- (define (leaf? tree)
- (and (empty? (cadr tree)) (empty? (caddr tree))))
- (define (RemoveOneDeviant tree)
- (if (empty? tree) '()
- (cond
- ((and (empty? (cadr tree)) (empty? (caddr tree))) (list (car tree) (RemoveOneDeviant (cadr tree)) (RemoveOneDeviant (caddr tree))))
- ((empty? (caddr tree)) (list (caadr tree) (RemoveOneDeviant (cadadr tree)) (RemoveOneDeviant (car (cddadr tree)))))
- ((empty? (cadr tree)) (list (caaddr tree) (RemoveOneDeviant (car (cdaddr tree))) (RemoveOneDeviant (cadr (cdaddr tree)))) )
- (else (list (car tree) (RemoveOneDeviant (cadr tree)) (RemoveOneDeviant (caddr tree)))) )))
- (define (everyboth tree)
- (if (leaf? tree)
- #t
- (and (not (or (null? (cadr tree)) (null? (caddr tree)))) (everyboth (cadr tree)) (everyboth (caddr tree)))))
- (define (Sol3 tree)
- (define (computing tree1)
- (if (everyboth tree1) tree1
- (computing (RemoveOneDeviant tree1))))
- (if (empty? tree) null
- (if (and (not (empty? (cadr tree))) (empty? (caddr tree))) (list (car tree) (computing (cadr tree)) null)
- (if (and (empty? (cadr tree)) (not (empty? (caddr tree)))) (list (car tree) null (computing (caddr tree)))
- (computing tree)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement