每个人,我想重写一个变专业版,使其成为一个 专业组合,有想法吗? 例如,输入列表'(1 2 2) pu变成((1 2 2)(1 2 2)(2 1 2)(2 2 1)(2 1 2)(2 2 1)) 我希望它变成((1 2 2)(2 1 2)(2 2 1))
(defun test-company--permutations(lst) (如果(不是第一) '(零) (cl-mapcan (lambda(e) (mapcar(lambda(perm)(cons e perm))) (test-company--permutations(cl-remove e lst:count 1))) lst))) (test-company--permutations'(1 2 2))
答案 0 :(得分:0)
(defun test-company--permutations (lst)
(if (not lst)
'(nil)
(cl-mapcan
(lambda (e)
(mapcar (lambda (perm) (cons e perm))
(test-company--permutations (cl-remove e lst :count 1))))
lst)))
(test-company--permutations '(1 2 2))