all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* all-substance.el
@ 2024-07-10  1:54 Emanuel Berg
  2024-07-11 17:59 ` all-substance.el Emanuel Berg
  0 siblings, 1 reply; 2+ messages in thread
From: Emanuel Berg @ 2024-07-10  1:54 UTC (permalink / raw)
  To: help-gnu-emacs

Here is another interesting program, and very substantial - or
have a look. Maybe the initial function can be improved?

The purpose is to compute the total amount of the substance
after some days and half-time for that substance.

The assumption is consumption is evenly distributed, i.e.
the same every day.

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

(require 'cl-lib)

(defun half-time-to-day-drop (ht)
  (if (< ht 24)
      (/ ht 24 2.0)
    (- 1 (/ 24 ht 2.0)) ))

;; (half-time-to-day-drop 12) ; 0.25
;; (half-time-to-day-drop 48) ; 0.75

(defun all-substance (q d ht)
  "Q is quantity, D is days, HT is half-time."
  (cl-loop
    with daily    = (/ q d 1.0)
    with day-drop = (half-time-to-day-drop ht)
    for i downfrom (1- d) to 0
    sum (* daily (expt day-drop i)) into total
    finally return (message "daily %.2f, days %d, total %.2f" daily d total) ))

;; (all-substance  5  10    6) ; daily 0.50, days  10, total  0.57
;; (all-substance 50 100    6) ; daily 0.50, days 100, total  0.57
;; (all-substance 50  50 6000) ; daily 1.00, days  50, total 47.63

(provide 'all-substance)

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




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-11 17:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-10  1:54 all-substance.el Emanuel Berg
2024-07-11 17:59 ` all-substance.el Emanuel Berg

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.