I’m looking for an algorithm to calculate total cost of licenses purchased based on the “FogBugz for your server” pricing scheme (http://www.fogcreek.com/FogBugz/PriceList.html).
Fogbugz pricing is:
- 1 License $299
- 5 License Pack $999
- 10 License Pack $1,899
- 20 License Pack $3,499
- 50 License Pack $7,999
If you ask a quote for let’s say 136 licenses they calculate it as $22,694.
How can I do this in C# or LINQ?
Any help will be appreciated.
The accepted answer, whilst an elegant piece of code from a programmer’s point of view, does not give the best possible price for the customer and therefore might not be an elegant solution from the customer’s point of view. For example when n = 4, the accepted answer gives $1196, but a customer would obviously prefer to choose the 5 license pack and pay just $999 instead.
It is possible to construct an algorithm which can calculate the minimum price possible that the customer can pay to purchase their required number of licenses. One way of doing this is to use dynamic programming. I think something like this might do the trick:
Output:
Update Producing a breakdown is a little more complicated, but I definitely think it will be beneficial for your customers. You could do it something like this (assuming printing to the console, although a real program would probably output to a web page):
Output: