I don't really know what to call this problem. I need this is for one of my projects. It will be programmed in javascript so edge cases can be handled. I'll try to frame this like a textbook question.
If this is not possible, anything close to this behaviour will work too.
Problem:
I have a fixed number of some item, apples for example, that cannot exist in a broken state (i.e. must be integers). I need to giveaway these apples to villagers in an exponentially decaying fashion at certain intervals (fixed integer) before a fixed end time. The number of apples given on the first distribution will be pre-defined. There should be no apples left after the end time.
Given (user defined) parameters:
$X =$ Total number of apples
$A =$ Number of apples on first distribution
$I =$ Time interval (integer)
$T =$ Total time for distribution (integer)
The end time will be a multiple of time interval, so $T = iI$ of which, either $I$ and $i$ are given or $I$ and $T$.
I need a function $f(x)$ that returns an integer $f(nI)$ (where $n$ is an integer). The domain of time is $(0 \le t \le T)$
so the results should be
$y(0) = A$
$y(T+) = 0$
$y(0I) + y(1I) + y(2I) + ... + y(iI) = X$
$OR$
$A + y(1I) + y(2I) + ... + y(T) = X$
Graph should look something like this: desmos, image
(note: this is not a perfect example as the values are not integers and don't add up to $X$)
My progress so far:
I have tried using the typical half- life based exponential decay functions but couldn't get the desired output
Repeated division by an integer and taking the quotient would give you what you need. Terminate when quotient is less than divisor.
Eg:
$$\array { dividend & divisor & quotient & remainder \\ \hline 1000 & 7 & 142 & 6 \\ 142 & 7 & 20 & 2 \\ 20 & 7 & 2 & 6 }$$
The sequence of quotients will have exponential falloff. You can get different types of sequences with different divisors. For eg: try $2$ for the longest possible sequence (using integer division).
The length of sequence is dependent on the initial dividend and the divisor:
$$length = \lfloor \log_{divisor} (dividend) \rfloor$$
The sequence
$$2 \times 7^3, 6 \times 7^2, 2 \times 7^1, 6 \times 7^0 = 686, 294, 14, 6$$
will also give you exponential decay, and will sum up to the dividend (1000 in this case).
This comes from the base-$r$ representation of an integer.
If you are given $X:$ total number of objects and $A:$ total initial distribution, what do you think is the first quotient and remainder? What is the first divisor? Hint: $divisor = \lfloor {X \over A} \rfloor$.
But we are also given $T:$ total time for distribution and $I:$ time interval for distribution, so you can compute $n = \lceil {T \over I} \rceil$ to get the number of intervals. This means the
$$balance = initial value - initial distribution$$
needs to be distributed over $n$ intervals. So,
$$divisor = {balance \over n}$$
Then use the algorithm using $balance, divisor$ as parameters.