gpt4 book ai didi

C#高级排列场景

转载 作者:行者123 更新时间:2023-11-30 13:49:30 24 4
gpt4 key购买 nike

我想知道如何根据以下信息找到所有组合:

我从一个 JSON 数据集开始:

var choices = { 1: {'Q': 100, 'R': 150, 'W' : 250, 'T', 30},
2: {'Q': 90, 'R': 130, 'W' : 225, 'T', 28},
3: {'Q': 80, 'R': 110, 'W' : 210, 'T', 25},
4: {'Q': 70, 'R': 90, 'W' : 180, 'T', 22},
5: {'Q': 60, 'R': 70, 'W' : 150, 'T', 18},
6: {'Q': 50, 'R': 50, 'W' : 110, 'T', 15},
7: {'Q': 40, 'R': 30, 'W' : 80, 'T', 11},
8: {'Q': 30, 'R': 25, 'W' : 50, 'T', 8},
9: {'Q': 20, 'R': 10, 'W' : 25, 'T', 5},
10: {'Q': 10, 'R': 5, 'W' : 15, 'T', 3}
};

我想弄清楚的是如何获取此数据集,并在为每一行选择“Q”、“R”、“W”或“T”元素时生成所有可能的组合。

所以我希望我的最终结果是这样的

var allChoices = { 0: {1: {'Q': 100},
2: {'R': 130},
3: {'W' : 210},
4: {'W' : 180},
5: {'T', 18},
6: {'R': 50,},
7: {'Q': 40,},
8: {'T', 8},
9: {'R': 10},
10: {'W' : 15},
},
1: {...},
...
1048576: {...}

};

我使用 JSON 是因为我认为它最容易可视化,但有谁知道我如何在 C# 中实现这一点?

如果这还不够清楚,请告诉我,我很难弄清楚如何提出这个问题。

最佳答案

这是一个以 4 为基数的 10 位数字。

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();
}
}

关于C#高级排列场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9314681/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com