From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: all-substance.el Date: Thu, 11 Jul 2024 19:59:27 +0200 Message-ID: <87zfqnizcw.fsf@dataswamp.org> References: <87o776ko43.fsf@dataswamp.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1534"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: help-gnu-emacs@gnu.org Cancel-Lock: sha1:/zyE3eoFpoMmSiHooSQsYuHg1kE= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jul 12 11:41:45 2024 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sSCmf-0000Ax-Kx for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 12 Jul 2024 11:41:45 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sSCm8-0000kX-8D; Fri, 12 Jul 2024 05:41:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRy51-0005kr-Ey for help-gnu-emacs@gnu.org; Thu, 11 Jul 2024 13:59:43 -0400 Original-Received: from ciao.gmane.io ([116.202.254.214]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRy4z-0000TH-Lk for help-gnu-emacs@gnu.org; Thu, 11 Jul 2024 13:59:43 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1sRy4t-000AA6-RA for help-gnu-emacs@gnu.org; Thu, 11 Jul 2024 19:59:35 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Mail-Copies-To: never Received-SPF: pass client-ip=116.202.254.214; envelope-from=geh-help-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 12 Jul 2024 05:41:10 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:147150 Archived-At: > Here is another interesting program, and very substantial Added `wash-out', so now we have wash on but also wash of. See results in particular with half time 6 hours in the below examples for unexpected things, to most. Also added docstrings and a bunch of stuff. ;;; -*- 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 &optional verbose day-q) "Q is the quantity, for example 10. This is a number; do not use a unit. D is the number of days, for example 20. HT is the half-time in hours, for example 6. Set VERBOSE to return a string. Set DAY-Q if Q instead is submitted the daily quantity, for example 0.5." (cl-loop with daily = (if day-q q (/ 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 (if verbose (message "daily %.2f, days %d, total %.2f" daily d total) total) )) ;; (all-substance 300 365 6) ; 0.94 ;; (all-substance 0.5 30 6 nil t) ; 0.57 ;; (all-substance 365 365 6 t) ; daily 1.00, days 365, total 1.14 (defun wash-out (q ht &optional days) (or days (setq days 5)) (cl-loop with day-drop = (half-time-to-day-drop ht) for d from 1 to days collect (* q (expt day-drop d)) into res finally return res) ) ;; (wash-out 1.14 6) ; 0.1 1 day w/o resupply ;; 0.02 2 .. ;; 0.002 3 .. ;; 0.0003 4 .. ;; 0.00003 5 .. (provide 'all-substance) -- underground experts united https://dataswamp.org/~incal