Formula for this diminishing function

95 Views Asked by At

I'm trying to write a function for a game where points accumulated becomes less effective as they get more.

Input Value: 2000

Interval: 500

For every interval reached, decrease the effectivity of remaining input value by half. For example.

0 ~ 500 = 500 (1:1 conversion)

501 ~ 1000 = 250 (2:1 conversion)

1001 ~ 1500 = 125 (4:1 conversion)

1501 ~ 2000 = 62.5 (8:1 conversion)

Then get the total of the above to come up with the final value

Final = 500 + 250 + 125 + 62.5

Final = 937.5

How would I write this in a formula without recursions?

1

There are 1 best solutions below

3
On BEST ANSWER

Your sum is a geometric sum, and a standard way to find the closed form for the sum is \begin{eqnarray*} 500+250+125+62.5&=&500\times1+500\times\frac{1}{2}+500\times\frac{1}{4}+500\times\frac{1}{8}\\ &=&500\times\left(\frac1{2^0}+\frac1{2^1}+\frac1{2^2}+\frac1{2^3}\right), \end{eqnarray*} where the sum has the following nice property; $$\left(1-\frac{1}{2}\right)\left(\frac1{2^0}+\frac1{2^1}+\frac1{2^2}+\frac1{2^3}\right)=1-\frac{1}{2^4},$$ which shows that $$\frac1{2^0}+\frac1{2^1}+\frac1{2^2}+\frac1{2^3}=\frac{1-\frac{1}{2^4}}{1-\frac{1}{2}}=2\left(1-\frac{1}{2^4}\right).$$ So your original sum can be compactly written as $$500+250+125+62.5=500\times2\left(1-\frac{1}{2^4}\right).$$ For different interval sizes or input values, you can change the values $500$ and $4=\frac{2000}{500}$ accordingly.