LISP - How to get the average length for nested li

2019-07-16 15:13发布

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?

1条回答
The star\"
2楼-- · 2019-07-16 16:09
(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. :)

查看更多
登录 后发表回答