Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; See https://programmingpraxis.com/2016/10/07/sticks/
- (defun stick (s)
- (setf s (sort s #'<))
- (let ((cost 0) (the-sum 0))
- (do ((x (pop s) (or (null s) (pop s))))
- ((null s) cost)
- (setf the-sum (+ x (car s))
- cost (+ cost the-sum)
- s (insert-sorted the-sum (cdr s))))))
- (defun insert-sorted (obj lst)
- (if (null lst)
- (cons obj nil)
- (if (< obj (car lst))
- (cons obj lst)
- (cons (car lst) (insert-sorted obj (cdr lst))))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement