Code: Select all
(define (nesting lst)
(cond ((null? lst) 0)
((atom? lst) 0)
(true (max (+ 1 (nesting (first lst)))
(nesting (rest lst))))
)
)
(nesting '(a (((b c (d)))) (e) ((f)) g))
;-> 5
Thanks.
Code: Select all
(define (nesting lst)
(cond ((null? lst) 0)
((atom? lst) 0)
(true (max (+ 1 (nesting (first lst)))
(nesting (rest lst))))
)
)
(nesting '(a (((b c (d)))) (e) ((f)) g))
;-> 5
Code: Select all
(define (nesting lst)
(if (null? lst) 0
(atom? lst) 0
(+ 1 (apply max (map nesting lst)))))
Code: Select all
(define (nesting lst prev (t 0))
(if (= lst prev)
t
(nesting (flat lst 1) lst (inc t))))
> (nesting '(a (((b c (d)))) (e) ((f)) g))
5