こんにちは皆さん、ネストされたリストの平均を見つけるためのソリューションを実装しました。それで、私の歓声でより良い解決策や考えられるエラーを考えてもらえないかと思っていました.
; takes a nested list and return a flattened list
(defun flatten-list (list)
(cond
((null list) list)
((atom list) (list list))
((list (first list))
(append (flatten-list (first list))
(flatten-list (rest list))))
(t
(append (list (first list))
(flatten-list (rest list))))
))
;takes a flattened list and return the sum of the numbers
(defun sum-list (list)
(cond ((null list)
0)
(t
(+ (first list) (sum-list(rest list))))
))
;uses the flatten-list and nested-average to find the average
(defun nested-average (list)
(sum-list (flatten-list list))
(defvar flat-lis)
(setf flat-list (flatten-list list))
(/ (sum-list flat-list) (length flat-list)
))