【问题标题】:How can I rewrite the pemutations programe become a combination programe?如何将排列程序重写为组合程序?
【发布时间】:2019-05-17 02:34:47
【问题描述】:

每个人,我想重写一个 pumutation pro,让它成为一个 组合亲,有什么想法吗? 例如,输入列表 '(1 2 2) 推算变为 ((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) (如果(不是 lst) '(零) (cl-mapcan (λ (e) (mapcar (lambda (perm) (cons e perm)) (测试公司--排列 (cl-remove e lst :count 1)))) lst))) (test-company--permutations '(1 2 2))

【问题讨论】:

    标签: elisp


    【解决方案1】:
    (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))
    

    【讨论】:

      猜你喜欢
      • 2014-03-17
      • 2018-05-22
      • 1970-01-01
      • 1970-01-01
      • 2022-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多