gpt4 book ai didi

sorting - 从 lisp 中的输入流中读取多项式

转载 作者:太空宇宙 更新时间:2023-11-03 19:02:34 26 4
gpt4 key购买 nike

从列表 pl 中读取多项式(输入格式见下文)并将其作为排序列表返回。

示例:(ReadPolynomial2 '(99 0 17 200 3 150 8 200 0 0)) 应返回 ((99 0) (3 150) (25 200))

最佳答案

我不知道你是否还需要它,但这是一个可能的解决方案:

(defun ReadPolynomial2 (lst)
(let ((even-positions (loop for p in (cdr lst) by #'cddr collect p)))
(loop for p in (remove-duplicates even-positions)
collect (list (loop for x on lst by #'cddr
when (= p (second x))
sum (first x)) p))))

关于sorting - 从 lisp 中的输入流中读取多项式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12602784/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com