Is the below description a known formula/series?

107 Views Asked by At

Asked to implement a solution in code to the following description: suppose that from a library

On day one, 1 book can be borrowed. Then on the next two days, 2 additional books can be borrowed hence after two days 3 books had been borrowed and after three days, 5 books are out.

On the next three subsequent days (four,five, six), 3 books can be borrowed. In summary: After four days, 8 books are out After five days, 11 books are out After six days, 14 books are out

This continues indefinitely After seven days(4 books to be borrowed),18 books are out After eight days, 22 books out After nice and ten, 26 and 30 books respectively are out

Is someone able to spot a formula (sum or other) to determine how many books can be borrowed for a given D = number of days?

Many thanks, Yaron

2

There are 2 best solutions below

8
On

After $d$ days, where $$d=1+2+\dots+n+r=\frac{n(n+1)}2+r,\quad0\le r\le n,$$ the number of borrowed books is $$b_d=1^2+2^2+\dots+n^2+(n+1)r=\frac{n(n+1)(2n+1)}6+(n+1)r.$$

Given $d,$ the "rest" $r$ can be deduced from $n,$ which itself can be found as the index of the largest triangular number $\le d$: $$n=\left\lfloor\frac{\sqrt{8d+1}-1}2\right\rfloor.$$

As a check, here is a screenshot of the first values given by these formulas, on a spreadsheet of OpenOffice:

enter image description here

Note moreover that for large numbers $d$, these direct formulas are less calculation-consuming than iterative or recursive ones.

6
On

One formula is, for the number of books $b$ and the number of a given day $D$:

$$b=\sum_{k=1}^D\left\lfloor\frac{1}{2}+\sqrt{2k}\right\rfloor,$$
where $(\lfloor\cdot\rfloor)$ is the floor function and $(\sum_{k=1}^D\cdot)$ is the summation of $D$ terms.

How to read this:

For day $D=1$, we calculate one term, namely $(\frac{1}{2}+\sqrt2)\approx 1.9$ and then round this down to the closest integer, in this case $b_{D=1}=1$.

For day $D=2$, we calculate two terms, namely again $(\frac{1}{2}+\sqrt2)\approx 1.9$ which we round down to $1$, and also $(\frac{1}{2}+\sqrt4)=2.5$ and then round this down to the closest integer, in this case $2$, to add them together. So, $b_{D=2}=1+2=3$.