;; key search words: drop cutoff pipe waste
;; This is a revised version fixing bugs in earler versions
(defun c:test (/ lst maxlen explst)
(setq lst'((23 7.65) (10 5.30) (54 3.67) (67 2.66) (44 9.71) (120 4.0)))
(setq maxlen 12.01)
(mapcar (function
(lambda (x) (if explst
(repeat (car x) (setq explst (cons (cadr x) explst)))
(progn
(setq explst (list (cadr x)))
(repeat (1- (car x)) (setq explst (cons (cadr x) explst)))
)
))) lst)
(print (setq clst (get_cutlist explst maxlen)))
(print "Number of Lengths ")(princ (length clst))
;(print "Drops")
;(mapcar '(lambda(x) (print (- MaxLen (apply '+ x)))) clst)
(princ)
)
;; CAB 03/10/06
;; updated 12/27/06
;; updated 01/22/09
;; updated 01/23/09
(defun get_cutlist (lst maxlen / cutlst itm ptr tl x finallst remove-at tmp tp)
;; (RemoveNth 3 '(0 1 2 3 4 5)) CAB 12/27/2006
(defun removeNth (i lst)
(setq i (1+ i))
(vl-remove-if '(lambda (x) (zerop (setq i (1- i)))) lst)
)
;; sort the list with largest first
(setq lst (mapcar '(lambda (x) (nth x lst)) (vl-sort-i lst '>)))
;; catch any length over MaxLen & break them
(if (not (vl-every '(lambda (x) (<= x MaxLen)) lst))
(progn
(while (> (setq tmp (car lst)) MaxLen)
(setq lst (cdr (append lst (list MaxLen (- tmp MaxLen)))))
)
(setq lst (mapcar '(lambda (x) (nth x lst)) (vl-sort-i lst '>)))
)
)
;; step through lst
(if (= (length lst) 1)
(setq finallst (list lst))
(progn
(while lst
(setq cutlst (list (car lst)) ; start new cutlist w/ first item
lst (reverse (cdr lst)) ; remove first item
eol (1- (length lst)) ; point to end of list
tl (apply '+ cutlst) ; total length so far
ptr 0
)
;; build the cutlst
(while
(cond
((null lst) nil)
((> ptr eol) nil)
((< (+ (nth ptr lst) tl) MaxLen)
(setq cutlst (cons (nth ptr lst) cutlst)
tl (+ tl (car cutlst))
lst (removeNth ptr lst)
eol (1- eol)
)
)
((setq ptr (1+ ptr)))
)
)
;; no more cuts fit, go to next
(setq finallst (cons cutlst finallst)
cutlst nil
lst (reverse lst)
)
)
)
)
finallst
)
Not sure you were working with the latest versions.You're right, I missed that one in my searching.
http://www.theswamp.org/index.php?topic=26955.msg326631#msg326631
Maybe this will get you closer to your goal.Thank you Alan,