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 912319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:21:35+00:00 2026-05-15T17:21:35+00:00

I have a coding/maths problem that I need help translating into C#. It’s a

  • 0

I have a coding/maths problem that I need help translating into C#. It’s a poker chip calculator that takes in the BuyIn, the number of players and the total amount of chips for each colour (there are x amount of colours) and their value.

It then shows you every possible combination of chips per person to equal the Buy In. The user can then pick the chipset distribution they would like to use. It’s best illustrated with a simple example.

  • BuyIn: $10
  • Number of Players: 1
  • 10 Red Chips, $1 value
  • 10 Blue Chips, $2 value
  • 10 Green Chips, $5 value

So, the possible combinations are:

R/B/G

  • 10/0/0
  • 8/1/0
  • 6/2/0
  • 5/0/1
  • 4/3/0
  • 2/4/0
  • 1/2/1

etc.

I have spent a lot of time trying to come up with an algorithm in C#/.NET to work this out. I am stumbling on the variable factor – there’s usually only 3 or 4 different chips colours in a set, but there could be any amount. If you have more than one player than you have to count up until TotalChips / NumberOfPlayers.

I started off with a loop through all the chips and then looping from 0 up to NumberOfChips for that colour. And this is pretty much where I have spent the last 4 hours… how do I write the code to loop through x amount of chips and check the value of the sum of the chips and add it to a collection if it equals the BuyIn? I need to change my approach radically methinks…

Can anyone put me on the right track on how to solve this please? Pseudo code would work – thank you for any advice!

The below is my attempt so far – it’s hopeless (and wont compile, just an example to show you my thought process so far) – Might be better not to look at it as it might biased you on a solution…

   private void SplitChips(List<ChipSuggestion> suggestions)
    {

        decimal valueRequired = (decimal)txtBuyIn.Value;
        decimal checkTotal = 0;
        ChipSuggestion suggestion;

        //loop through each colour
        foreach (Chip chip in (PagedCollectionView)gridChips.ItemsSource)
        {
                //for each value, loop through them all again
                foreach (Chip currentChip in (PagedCollectionView)gridChips.ItemsSource)
                {
                    //start at 0 and go all the way up
                    for (int i = 0; i < chip.TotalChipsInChipset; i++)
                    {
                        checkTotal = currentChip.ChipValue * i;

                        //if it is greater than than ignore and stop
                        if (checkTotal > valueRequired)
                        {
                            break;
                        }
                        else
                        {
                            //if it is equal to then this is a match
                            if (checkTotal == valueRequired)
                            {
                                suggestion = new ChipSuggestion();
                                suggestion.SuggestionName = "Suggestion";

                                chipRed.NumberPerPlayer = i;
                                suggestion.Chips.Add(chipRed);

                                chipBlue.NumberPerPlayer = y;
                                suggestion.Chips.Add(chipBlue);

                                chipGreen.NumberPerPlayer = 0;
                                suggestion.Chips.Add(chipGreen);

                                //add this to the Suggestion
                                suggestions.Add(suggestion);
                                break;
                            }


                    }
                }
            }
        }
    }
  • 1 1 Answer
  • 0 Views
  • 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-15T17:21:36+00:00Added an answer on May 15, 2026 at 5:21 pm

    Here’s an implementation that reads the number of chips, the chips (their worth and amount) and the buyin and displays the results in your example format. I have explained it through comments, let me know if you have any questions.

    class Test
    {
        static int buyIn; 
        static int numChips;
        static List<int> chips = new List<int>(); // chips[i] = value of chips of color i
        static List<int> amountOfChips = new List<int>(); // amountOfChips[i] = number of chips of color i
    
        static void generateSolutions(int sum, int[] solutions, int last)
        {
            if (sum > buyIn) // our sum is too big, return
                return;
    
            if (sum == buyIn) // our sum is just right, print the solution
            {
                for (int i = 0; i < chips.Count; ++i)
                    Console.Write("{0}/", solutions[i]);
                Console.WriteLine();
    
                return; // and return
            }
    
            for (int i = last; i < chips.Count; ++i) // try adding another chip with the same value as the one added at the last step. 
                                                     // this ensures that no duplicate solutions will be generated, since we impose an order of generation
                if (amountOfChips[i] != 0)
                {
                    --amountOfChips[i]; // decrease the amount of chips
                    ++solutions[i]; // increase the number of times chip i has been used
    
                    generateSolutions(sum + chips[i], solutions, i); // recursive call
    
                    ++amountOfChips[i]; // (one of) chip i is no longer used
                    --solutions[i]; // so it's no longer part of the solution either
                }
        }
    
        static void Main()
        {
            Console.WriteLine("Enter the buyin:");
            buyIn = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter the number of chips types:");
            numChips = int.Parse(Console.ReadLine());
            Console.WriteLine("Enter {0} chips values:", numChips);
            for (int i = 0; i < numChips; ++i)
                chips.Add(int.Parse(Console.ReadLine()));
    
            Console.WriteLine("Enter {0} chips amounts:", numChips);
            for (int i = 0; i < numChips; ++i)
                amountOfChips.Add(int.Parse(Console.ReadLine()));
    
            int[] solutions = new int[numChips];
    
            generateSolutions(0, solutions, 0);
        }
    } 
    

    Enter the buyin:
    10
    Enter the number of chips types:
    3
    Enter 3 chips values:
    1
    2
    5
    Enter 3 chips amounts:
    10
    10
    10
    10/0/0/
    8/1/0/
    6/2/0/
    5/0/1/
    4/3/0/
    3/1/1/
    2/4/0/
    1/2/1/
    0/5/0/
    0/0/2/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 470k
  • Answers 470k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I've investigated this further and discovered that the problem is… May 16, 2026 at 3:07 am
  • Editorial Team
    Editorial Team added an answer You didn't specify EXACTLY what you want as far as… May 16, 2026 at 3:07 am
  • Editorial Team
    Editorial Team added an answer First of all, jQuery has nothing to do with this.… May 16, 2026 at 3:07 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.