Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 737877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:46:20+00:00 2026-05-14T07:46:20+00:00

I’m looking for an algorithm to calculate total cost of licenses purchased based on

  • 0

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.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:46:21+00:00Added an answer on May 14, 2026 at 7:46 am

    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:

    int calculatePrice(int n, Dictionary<int, int> prices)
    {
    
        int[] best = new int[n + prices.Keys.Max()];
        for (int i = 1; i < best.Length; ++i)
        {
            best[i] = int.MaxValue;
            foreach (int amount in prices.Keys.Where(x => x <= i))
            {
                best[i] = Math.Min(best[i],
                    best[i - amount] + prices[amount]);
            }
        }
        return best.Skip(n).Min();
    }
    
    void Run()
    {
        Dictionary<int, int> prices = new Dictionary<int, int> {
            { 1, 299 },
            { 5, 999 },
            { 10, 1899 },
            { 20, 3499 },
            { 50, 7999 }
        };
    
        Console.WriteLine(calculatePrice(136, prices));
        Console.WriteLine(calculatePrice(4, prices));
    }
    

    Output:

    22694
    999
    

    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):

    using System;
    using System.Linq;
    using System.Collections.Generic;
    
    class Program
    {
        static Dictionary<int, int> prices = new Dictionary<int, int> {
                { 1, 299 },
                { 5, 999 },
                { 10, 1899 },
                { 20, 3499 },
                { 50, 7999 }
        };
    
        class Bundle
        {
            public int Price;
            public Dictionary<int, int> Licenses;
        }
    
        Bundle getBestBundle(int n, Dictionary<int, int> prices)
        {
            Bundle[] best = new Bundle[n + prices.Keys.Max()];
            best[0] = new Bundle
            {
                Price = 0,
                Licenses = new Dictionary<int, int>()
            };
    
            for (int i = 1; i < best.Length; ++i)
            {
                best[i] = null;
                foreach (int amount in prices.Keys.Where(x => x <= i))
                {
                    Bundle bundle = new Bundle
                    {
                         Price = best[i - amount].Price + prices[amount],
                         Licenses = new Dictionary<int,int>(best[i - amount].Licenses)
                    };
    
                    int count = 0;
                    bundle.Licenses.TryGetValue(amount, out count);
                    bundle.Licenses[amount] = count + 1;
    
                    if (best[i] == null || best[i].Price > bundle.Price)
                    {
                        best[i] = bundle;
                    }
                }
            }
            return best.Skip(n).OrderBy(x => x.Price).First();
        }
    
        void printBreakdown(Bundle bundle)
        {
            foreach (var kvp in bundle.Licenses) {
                Console.WriteLine("{0,2} * {1,2} {2,-5} @ ${3,4} = ${4,6}",
                   kvp.Value,
                    kvp.Key,
                    kvp.Key == 1 ? "user" : "users",
                    prices[kvp.Key],
                    kvp.Value * prices[kvp.Key]);
            }
    
            int totalUsers = bundle.Licenses.Sum(kvp => kvp.Key * kvp.Value);
    
            Console.WriteLine("-------------------------------");
            Console.WriteLine("{0,7} {1,-5}           ${2,6}",
                totalUsers,
                totalUsers == 1 ? "user" : "users",
                bundle.Price);
        }
    
        void Run()
        {
            Console.WriteLine("n = 136");
            Console.WriteLine();
            printBreakdown(getBestBundle(136, prices));
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("n = 4");
            Console.WriteLine();
            printBreakdown(getBestBundle(4, prices));
        }
    
        static void Main(string[] args)
        {
            new Program().Run();
        }
    }
    

    Output:

    n = 136
    
     2 * 50 users @ $7999 = $ 15998
     1 * 20 users @ $3499 = $  3499
     1 * 10 users @ $1899 = $  1899
     1 *  5 users @ $ 999 = $   999
     1 *  1 user  @ $ 299 = $   299
    -------------------------------
        136 users           $ 22694
    
    
    n = 4
    
     1 *  5 users @ $ 999 = $   999
    -------------------------------
          5 users           $   999
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a small JavaScript validation script that validates inputs based on Regex. I
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.