LISP-如何获取嵌套列表的平均长度? [英] LISP - How to get the average length for nested lists?

查看:180
本文介绍了LISP-如何获取嵌套列表的平均长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题.我需要从以下列表中获取平均长度:(1 (2 3 4) 5 (6 7) 8 (9)).应该是2.我不知道从哪里开始...

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...

我试图从(1 (2 3 4) 5 (6 7) 8 (9))获取(1 2 3 4 5 6 7 8 9),但是我失败了,因为(reduce #'append list-name)无法正常工作.

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.

我知道如何计算,但是我需要获取所有列表(1(2 3 4)5(6 7)8(9)) 像这样:

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)

但是我不知道如何.

你能给我些帮助吗?

推荐答案

(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. :)

这篇关于LISP-如何获取嵌套列表的平均长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆