Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm for Fogbugz pricing scheme

Tags:

c#

algorithm

linq

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.

like image 574
Anon1865 Avatar asked Apr 21 '10 18:04

Anon1865


1 Answers

int licenses = 136;
int sum = 0;

while (licenses > 0)
{
    if (licenses >= 50)      { sum += 7999; licenses -= 50; }
    else if (licenses >= 20) { sum += 3499; licenses -= 20; }
    else if (licenses >= 10) { sum += 1899; licenses -= 10; }
    else if (licenses >= 5)  { sum += 999;  licenses -= 5; }
    else                     { sum += 299;  licenses -= 1; }
}

// sum == 22694

or

int licenses = 136;
int sum = 7999 * Math.DivRem(licenses, 50, out licenses)
        + 3499 * Math.DivRem(licenses, 20, out licenses)
        + 1899 * Math.DivRem(licenses, 10, out licenses)
        +  999 * Math.DivRem(licenses,  5, out licenses)
        +  299 * licenses;

// sum == 22694
like image 112
dtb Avatar answered Oct 28 '22 13:10

dtb