Advertisement
Guest User

Untitled

a guest
May 25th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. ;; Flatten tree then count
  2. (define (count-leaves0 t)
  3. (accumulate (lambda (x total) (+ total 1)) 0
  4. (map (lambda (children) children)
  5. (enumerate-tree t))))
  6.  
  7.  
  8. (define (count-leaves1 t)
  9. (accumulate + 0
  10. (map (lambda (children)
  11. (if (pair? children)
  12. (count-leaves1 children)
  13. 1))
  14. t)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement