Skip to content

Instantly share code, notes, and snippets.

@kouddy
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kouddy/ce7a63dbd7c919840593 to your computer and use it in GitHub Desktop.
Save kouddy/ce7a63dbd7c919840593 to your computer and use it in GitHub Desktop.
;; Flatten tree then count
(define (count-leaves0 t)
(accumulate (lambda (x total) (+ total 1)) 0
(map (lambda (children) children)
(enumerate-tree t))))
(define (count-leaves1 t)
(accumulate + 0
(map (lambda (children)
(if (pair? children)
(count-leaves1 children)
1))
t)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment