;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/eggs.el (require 'cl-lib) (defun boil-eggs (eggs pots) (when pots (setq eggs (sort eggs #'>)) (setq pots (sort pots #'>)) (setf (cdr (last pots)) pots) (let ((time 0)) (while eggs (cl-incf time (car eggs)) (setq eggs (cl-subseq eggs (min (car pots) (length eggs)))) (pop pots) ) time) )) ;; (boil-eggs '(5) ()) ; nil ;; (boil-eggs () '(5)) ; 0 ;; (boil-eggs '(5 7 8 10) '(2)) ; 17 ;; (boil-eggs '(5 7 8 10) '(2 3)) ; 15 (provide 'eggs)