C# advanced permutation scenario

后端 未结 4 938
北恋
北恋 2021-01-20 20:55

I am trying to figure how how to find all the combinations given the following information:

I start with a JSON dataset:

var choices = { 1: {\'Q\': 1         


        
4条回答
  •  迷失自我
    2021-01-20 21:46

    It's a 10 digit base 4 number.

    class Program
    {
        static void Main(string[] args)
        {
            int baseN = 4;
            int maxDigits = 10;
            var max = Math.Pow(baseN, maxDigits);
            for (int i = 0; i < max; i++)
            { // each iteration of this loop is another unique permutation
                var digits = new int[maxDigits];
                int value = i;
                int place = digits.Length - 1;
                while (value > 0)
                {
                    int thisdigit = value % baseN;
                    value /= baseN;
                    digits[place--] = thisdigit;
                }
    
                int choice = 0;
                foreach (var digit in digits)
                {
                    choice ++;
                    //Console.Write(digit);
                    switch (digit)
                    {
                        case 0: break; //choose Q from choice
                        case 1: break; //choose R from choice
                        case 2: break; //choose W from choice
                        case 3: break; //choose T from choice
                    }
                }
                //Console.WriteLine();
                // add it to your list of all permutations here
            }
            Console.WriteLine("Done")
            Console.ReadLine();
        }
    }
    

提交回复
热议问题