These are my code,
;;(calc-depth L)
;;The calc-depth function takes a list L and returns its depth.
;;The depth of a list is defined as the maximum level of "nesting" of a list.
;;A list with no sublists has a depth of 1; a list with sublists that don't have sublists has a depth of 2; a list with sublists that have sublists that don't have sublists has a depth of 3; and so on.
(define calc-depth
(lambda (L)
(cond
((empty? L) 1)
((list? (first L)) (+ (calc-depth (first L)) (calc-depth (rest L))))
(else (calc-depth (rest L))))))
(check-expect (calc-depth '()) 1)
(check-expect (calc-depth '(1 (2) 3)) 2)
(check-expect (calc-depth '(1 (2 (3) 4) 5)) 3)
(check-expect (calc-depth '(1 (2) 3 (4 (5)))) 3) ;;problem.

New Topic/Question
Reply



MultiQuote



|