Question

I have a problem. I need to get average length from this list: (1 (2 3 4) 5 (6 7) 8 (9)). It should be 2. And I have no idea where to start...

I tried to get (1 2 3 4 5 6 7 8 9) from (1 (2 3 4) 5 (6 7) 8 (9)) but I failed, because (reduce #'append list-name) isn't working.

I have idea how to calculate this but I need to get all lists inside (1 (2 3 4) 5 (6 7) 8 (9)) like this:

list1 = (1 5 8)
list2 = (2 3 4)
list3 = (6 7)
list4 = (9)

But I don't know how.

Can u give me some help?

Was it helpful?

Solution

(defun nested-lists-average-length (ls &aux (i 0) (n 0))
    (dolist (a ls (float (/ _______)))
      (if (_______ a) 
        (progn (_______ i) 
               (incf n (_______ a) )))))

Fill ... in ... the ... blanks. :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top