- (defun c:qs123()
- ; 最节省母材材料?
- (setq b1 '(1.2 1.5 2.3 2.6 2.6 4.8 3.3 3.5 4.1 4.2 4.3))
- (setq b1 '(1.2 1.5 2.3 2.6 2.6 3.3 3.5 4.1 4.2 ))
- (setq b1 (vl-sort b1 '>))
- (setq kn 5 i 0 n 0 b2 b1 b4 '() b3 '() )
- (while (cdr b2)
- (setq t1 (car b2) b2 (cdr b2) t2 (cadr (reverse b2)) t3 (car (reverse b2)) );t3 最后一位
- (cond
- ((<= (+ t1 t2 t3) kn)(setq i (1+ i) b2 (reverse (cdr (cdr (reverse b2)))) b3 (cons (list t1 t2 t3) b3) ))
- ((<= (+ t1 t2 ) kn)(setq i (1+ i) b2 (cons t3 (cdr (cdr (reverse b2)))) b2 (reverse b2) b3 (cons (list t1 t2) b3) ))
- ((<= (+ t1 t3) kn)(setq i (1+ i) b2 (reverse (cdr (reverse b2))) b3 (cons (list t1 t3) b3) ))
- ((<= t1 kn)(setq i (1+ i) b3 (cons (list t1) b3) ))
- (t (print t1))
- )
- )
- (setq i (1+ i) b3 (cons b2 b3) )
- (print b1)
- (print (reverse b3))(princ i)
- (princ)
- )
是不是这样?你可以据此再改进。
命令: qs123
(4.2 4.1 3.5 3.3 2.6 2.6 2.3 1.5 1.2)
((4.2) (4.1) (3.5 1.5) (3.3 1.2) (2.6 2.3) 2.6) 6
|