Sorunum için 6'dan büyük bir sayım var. Bu listeden, tam olarak 6 kart uzunluğunda olan orijinal kartların olası tüm kombinasyonlarını içeren bir liste yapmak istiyorum.Tüm benzersiz konumlar bir listeden nasıl çıkarılır?
yüzden 01,02,03,04,05,06 nesne (bunlar benzersiz olmak zorunda ve sırası önemli değildir) 06,05,04,03,02,01 olarak benim için aynıdır
//STARTER list with more then 6 value's
List <ClassicCard> lowCardsToRemove = FrenchTarotUtil.checkCountLowCardForDiscardChien(handCards);
buldum ve kullanılan çözüm:
kamu statik Liste generateAllSubsetCombinations (object [] fullSet, ulong subsetSize) { (fullSet == null) { atmak yeni ArgumentException ("Değer olamaz eğer null. "," fullSet "); } } (subsetSize < 1) { yeni ArgumentException ("Alt küme boyutu 1 veya daha büyük olmalıdır.", "SubsetSize") atarsa; } } if ((ulong) fullSet.LongLength < subsetSize) { yeni ArgumentException atayın ("Alt küme boyutu tam kümedeki toplam giriş sayısından büyük olamaz.", "SubsetSize"); }
// All possible subsets will be stored here
List<object[]> allSubsets = new List<object[]>();
// Initialize current pick; will always be the leftmost consecutive x where x is subset size
ulong[] currentPick = new ulong[subsetSize];
for (ulong i = 0; i < subsetSize; i++) {
currentPick[i] = i;
}
while (true) {
// Add this subset's values to list of all subsets based on current pick
object[] subset = new object[subsetSize];
for (ulong i = 0; i < subsetSize; i++) {
subset[i] = fullSet[currentPick[i]];
}
allSubsets.Add(subset);
if (currentPick[0] + subsetSize >= (ulong)fullSet.LongLength) {
// Last pick must have been the final 3; end of subset generation
break;
}
// Update current pick for next subset
ulong shiftAfter = (ulong)currentPick.LongLength - 1;
bool loop;
do {
loop = false;
// Move current picker right
currentPick[shiftAfter]++;
// If we've gotten to the end of the full set, move left one picker
if (currentPick[shiftAfter] > (ulong)fullSet.LongLength - (subsetSize - shiftAfter)) {
if (shiftAfter > 0) {
shiftAfter--;
loop = true;
}
}
else {
// Update pickers to be consecutive
for (ulong i = shiftAfter+1; i < (ulong)currentPick.LongLength; i++) {
currentPick[i] = currentPick[i-1] + 1;
}
}
} while (loop);
}
return allSubsets;
}
http://stackoverflow.com/questions/127704/algorithm-to-return-all-combinations-of-k-elements-from-n –
gör 'n' değerlerinden değerler? istatistiklerde 'n'' k' ya da 'nCk' seçer mi? –
Her bir "k" nesnesinin, "n" değerlerinden, lengt n'nin değişken olduğu ve k lengt'in alway'in 6 olduğu her bir "com" nesnesini istiyorum. – schadowfax