Advertisement
PonaFly

Untitled

Mar 28th, 2019
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 1.35 KB | None | 0 0
  1. (define (Sol1 func tree)
  2.   (if (empty? tree) '()
  3.       (list (func (car tree)) (Sol1 func (cadr tree)) (Sol1 func (caddr tree)))))
  4.  
  5.  
  6. (define (leaf? tree)
  7.   (and (empty? (cadr tree)) (empty? (caddr tree))))
  8.  
  9. (define (RemoveOneDeviant tree)
  10.   (if (empty? tree) '()
  11.       (cond
  12.         ((and (empty? (cadr tree)) (empty? (caddr tree))) (list (car tree) (RemoveOneDeviant (cadr tree)) (RemoveOneDeviant (caddr tree))))
  13.         ((empty? (caddr tree)) (list (caadr tree) (RemoveOneDeviant (cadadr tree)) (RemoveOneDeviant (car (cddadr tree)))))
  14.         ((empty? (cadr tree)) (list (caaddr tree) (RemoveOneDeviant (car (cdaddr tree))) (RemoveOneDeviant (cadr (cdaddr tree)))) )
  15.        
  16.         (else (list (car tree) (RemoveOneDeviant (cadr tree)) (RemoveOneDeviant (caddr tree)))) )))
  17.  
  18. (define (everyboth tree)
  19. (if (leaf? tree)
  20. #t
  21. (and (not (or (null? (cadr tree)) (null? (caddr tree)))) (everyboth (cadr tree)) (everyboth (caddr tree)))))
  22.  
  23. (define (Sol3 tree)
  24.   (define (computing tree1)
  25.     (if (everyboth tree1) tree1
  26.         (computing (RemoveOneDeviant tree1))))
  27.   (if (empty? tree) null
  28.       (if (and (not (empty? (cadr tree))) (empty? (caddr tree))) (list (car tree) (computing (cadr tree)) null)
  29.           (if (and (empty? (cadr tree)) (not (empty? (caddr tree)))) (list (car tree) null (computing (caddr tree)))
  30.               (computing tree)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement