各配列の最初の要素を除いて、2D [mxn] 配列から可能なすべての組み合わせを生成したいと考えています。その要素は、残りの要素を意味する「タイプ」を表します。たとえば、配列がある場合
shirts[][] =
{
{"colour", "red", "blue", "green", "yellow"},
{"cloth", "cotton", "poly", "silk"},
{"type", "full", "half"}
};
望ましいアウトプットは、シャツのすべての可能性を組み合わせたものでなければなりません。上記の例では、
colour red
colour blue
...
cloth silk
type full
type half
colour red cloth cotton
colour red cloth poly
...
colour yellow type half
cloth cotton type full
...
cloth silk type half
colour red cloth cotton type full
...
colour yellow cloth silk type half
私はこのようなことを試しました(他のスタックオーバーフローの質問からも助けられました)
String shirts[][] =
{
{"colour", "red", "blue", "green", "yellow"},
{"cloth", "cotton", "poly", "silk"},
{"type", "full", "half"}
};
majorCombinations = new int[possibilities][shirts.length];
int currentCombination;
int offset = 1;
for (int i=0; i < shirts.length; i++)
{
currentCombination = 0;
while (currentCombination < possibilities)
{
for (int j=0; j < shirts[i].length; j++)
{
for (int k=0; k < offset; k++)
{
if (currentCombination < possibilities)
{
majorCombinations[currentCombination][i] = shirts[i][j];
currentCombination++;
}
}
}
}
offset *= shirts[i].length;
}
ただし、すべてのn個の組み合わせの値のみを提供します。つまり
colour cloth type
colour cloth full
...
yellow silk half
より小さな組み合わせは考慮されておらず、一般的でもありません。つまり、[mxn] 配列の場合です (n を固定する必要はありません)。VBA のヘルプをいただければ幸いです。C、Java、および C# に慣れています。前もって感謝します :)
編集:
これは、ここで尋ねた質問とは異なります。これは、問題の各配列から1 つの要素が取得されるデカルト積ではありません。私が必要とする出力には、この制限はありません。したがって、このシナリオの組み合わせの数 > リンクされた質問の組み合わせの数です。また、最初の列はコンテンツの記述子であり、コンテンツに付随する必要があります。