Adám
Given a **date** in the past (in the Gregorian calendar, no earlier than 1582-10-15, and in any reasonable format) and a **number** of days, compute the **ratio** (in any reasonable format, and with reasonable precision) of that number to the number of days in the inclusive date range, from the given date and until today (at running time).
### Examples (as of 2020-09-09):
date: **2020-08-31**
number: **4**
ratio: **0.4**
Why? There are 10 days in the range: **2020-08-31** (the given date), 2020-09-01, 2020-09-02, 2020-09-03, 2020-09-04, 2020-09-05, 2020-09-06, 2020-09-07, 2020-09-08, 2020-09-09 (today). **4** ÷ 10 = **0.4**
date: **2015-08-26**
number: **1544**
ratio: **0.8387**
wizzwizz4
xigoi
wizzwizz4
# 59 bytes
lambda d,n:n/-~(__import__("datetime").date.today()-d).days
[Try it online!][TIO-kffu55qo]
Python has a built-in date time; I assume that's a reasonable input format. Unfortunately, subtraction gives a value that's off by one; the infix `-~` (flip the bits, then negate) increments the denominator without requiring extra parentheses for precedence.
[Python 3]: https://docs.python.org/3/
[TIO-kffu55qo]: https://tio.run/##VYu9CsIwFIX3PMUlUwKx1tpFobi4@gCCECLpH5ibkF6HLL56pAaHbud83zkh0eTxmAfoHvll3NMasArPuN99hNazCz6S1oJbQz3NrueyWmNF3pok5M6uPS15iN7BfwTl9@tgFhgZS9DBjCRmDG8S/N6beAEuJXNbcfNIUzF2a64mFY5bjoWGuLJBjCIpcAqsVIBS5qZuanZih5a1Xw "Python 3 – Try It Online"
Answer #2
xigoi
# [Nim], 58 bytes
import times
proc r(d,n:auto):auto=n/(days(now()-d).int+1)
[Try it online!][TIO-kholqqfg]
[Nim]: http://nim-lang.org/
[TIO-kholqqfg]: https://tio.run/##LcyxCgIxDIDh3afI2GA974qT4KaDLi6Cc7kGjNqk9CKHT19FhJ9v/IVza5yLVgPjTNOiVB2huuRlG1@m@HMna5fie3Kis8NVwo7FlgM2Gm8KLGz7aHT5DtzgIZ@ieAh96D38w666TcDWqNCdH/PheKai8fos6QM "Nim – Try It Online"