Algorithm for calculating total cost in groups of N
I have a limited supply of objects and as the objects are purchased, the
price goes up accordingly in groups of N (every time N objects are bought,
price increases). When trying to purchase a number of objects, what is the
easiest way to calculate total cost?
Example:
I have 24 foo. For every N(example using 3) that are purchased, the price
increases by 1.
So if I buy 1 at the prices of 1 then there are 23 left and 2 left at the
price of 1.
After 1 has been purchased, someone wishes to buy 6. Well the total cost
would be = (2*1)+(3*2)+(1*3)
No comments:
Post a Comment