summaryrefslogtreecommitdiff
path: root/coding-exercises/2/35.rkt
blob: cc3057119c823fcd7a9b6a25011efb2f4667f2b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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))))