Reputation: 647
I'm sure this is simple enough for someone better at maths than me, but the solution is eluding me.
I need to take a number, the block chain height, which at every 500 thousand blocks, reduces the reward by 5%.
The original reward is 3 per block. So block 500001 would be 2.85, block 1,000,001 would be 2.7075, block 1,500,001 would be 2.572125, etc.
This happens all the way to block 30,000,000 so using case or if is not practical.
Upvotes: 1
Views: 66
Reputation: 3819
I can't quite tell if you need continuous reduction, or "sudden" reduction after crossing the next 500,000 (for example, is the reward at block 499,999 still 3%?).
Assuming you need "sudden" reduction, you first calculate the number of reductions.
var blocks = 10000000; // 10 million, just as an example
var reductions = Math.floor(blocks / 500000);
Then apply the reductions to your reward
var reward = 0.03 * Math.pow(0.95, reductions);
That will take off 5% (by multiplying by 0.95) the correct number of times. The result will be a decimal percent (like 0.0285 representing 2.85%, etc).
If you need a continuous reduction, you can actually just remove the Math.floor
from the calculation of reductions above.
Upvotes: 3