summaryrefslogtreecommitdiff
path: root/coding-exercises/2/35.rkt
diff options
context:
space:
mode:
Diffstat (limited to 'coding-exercises/2/35.rkt')
-rw-r--r--coding-exercises/2/35.rkt19
1 files changed, 19 insertions, 0 deletions
diff --git a/coding-exercises/2/35.rkt b/coding-exercises/2/35.rkt
new file mode 100644
index 0000000..cc30571
--- /dev/null
+++ b/coding-exercises/2/35.rkt
@@ -0,0 +1,19 @@
+#lang racket
+(require "../../shared/lists.rkt")
+
+(define (count-leaves t)
+ (accumulate
+ (lambda (x y)
+ (+ x y))
+ 0
+ (map
+ (lambda (x)
+ (if (pair? x)
+ (count-leaves x)
+ 1)) t)))
+
+(define test-tree (list 1 (list 2 (list 3 4) 5) (list 6 7)))
+((lambda ()
+ (display "testing")
+ (newline)
+ (display (count-leaves test-tree))))