Last active
August 29, 2015 14:19
-
-
Save kouddy/ce7a63dbd7c919840593 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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