From: Emanuel Berg <incal@dataswamp.org>
To: help-gnu-emacs@gnu.org
Subject: Re: problems of everyday life
Date: Wed, 16 Nov 2022 22:38:15 +0100 [thread overview]
Message-ID: <87zgcq4m2g.fsf@dataswamp.org> (raw)
In-Reply-To: MW4PR14MB5327CDDBF73BAD5754BD0B8DE7079@MW4PR14MB5327.namprd14.prod.outlook.com
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
next prev parent reply other threads:[~2022-11-16 21:38 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-15 15:19 problems of everyday life Emanuel Berg
2022-11-15 16:45 ` Heime
2022-11-15 16:46 ` Dmitry Gutov
2022-11-15 17:17 ` Heime
2022-11-16 12:02 ` Akib Azmain Turja
2022-11-15 18:38 ` tomas
2022-11-16 7:51 ` Juri Linkov
2022-11-16 12:10 ` Akib Azmain Turja
2022-11-16 20:39 ` Emanuel Berg
2022-11-17 3:04 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-11-17 4:56 ` Emanuel Berg
2022-11-17 5:48 ` tomas
2022-11-17 6:13 ` Yuri Khan
2022-11-17 6:25 ` Stefan Monnier
2022-11-16 14:31 ` Emanuel Berg
2022-11-16 14:54 ` Emanuel Berg
2022-11-16 16:14 ` Rudolf Adamkovič
2022-11-16 17:17 ` Emanuel Berg
2022-11-16 20:54 ` North Year
2022-11-16 21:06 ` Emanuel Berg
2022-11-16 21:30 ` Emanuel Berg
2022-11-16 21:38 ` Emanuel Berg [this message]
2022-11-17 6:33 ` Jean Louis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87zgcq4m2g.fsf@dataswamp.org \
--to=incal@dataswamp.org \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).