- (defun permutation (lst n / lst1 lst2 lstx lsty item)
- (if (and (> n 0) (<= n (length lst)))
- (progn
- (setq m 1
- lst1 (mapcar 'list lst)
- lsty lst1 ;_ 不定项
- )
- (while (< m n)
- (setq lst2 nil
- lstx lst1 ;_ 单项
- )
- (while (setq item (car lstx))
- (setq lstx (cdr lstx))
- (foreach x lsty
- (if (not (member (car item) x))
- (setq lst2 (append lst2 (list (append item x))))
- )
- )
- )
- (setq lsty lst2
- m (1+ m)
- )
- )
- lsty
- )
- )
- )
- (defun combination (lst n / lst1 lst2 lst3 L item)
- (if (setq lst1 (permutation lst n))
- (progn
- (while (setq item (car lst1))
- (setq lst1 (cdr lst1)
- L (length item)
- lst2 (permutation item L)
- )
- (foreach x lst1
- (if (member x lst2)
- (setq TorNil T)
- )
- )
- (if TorNil
- (setq TorNil nil)
- (setq lst3 (append lst3 (list item)))
- )
- )
- lst3
- )
- )
- )
- (defun cmbntn (lst1 n1 lst2 n2 / x-lst y-lst L n item xyLst)
- (setq x-lst (combination lst1 n1)
- y-lst (combination lst2 n2)
- L (length x-lst)
- n 0
- )
- (while (< n L)
- (setq item (nth n x-lst))
- (foreach y y-lst
- (setq xyLst (append xyLst (list (append item y))))
- )
- (setq n (1+ n))
- )
- xyLst
- )
|