help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problems of everyday life


From: Emanuel Berg
Subject: Re: problems of everyday life
Date: Wed, 16 Nov 2022 22:38:15 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

North Year wrote:

> This leads to a dynamic programming problem I guess.
>
> x eggs to be boiled each of which need x_i times to be
> boiled. y pots can be used to boil egges each of which has
> capacity to cook y_i eggs at one time.
>
> Never tried to writing algorithm codes in elisp. This would
> be interesting.

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/eggs.el

(require 'cl-lib)

(defun boil-eggs (eggs pots)
  (unless pots
    (error "No pot! Have you been smoking some weed in Sweeden?"))
  (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) ())            ; DNC
;; (boil-eggs  () '(5))           ; 0
;; (boil-eggs '(5 7 8 10)   '(2)) ; 17
;; (boil-eggs '(5 7 8 10) '(2 3)) ; 15

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]