math - C#: Dice Permutation without Repetition -


how can change c# code below list possible permutations without repetitions? example: result of 2 dice rolls produce 1,1,2 means 2,1,1 should not appear.

below code:

string[] permutate(int input) { string[] dice; int numberofdice = input; const int diceface = 6; dice = new string[(int)math.pow(diceface, numberofdice)]; int indexnumber = (int)math.pow(diceface, numberofdice); int range = (int)math.pow(diceface, numberofdice) / 6; int dicenumber = 1; int counter = 0; (int = 1; <= indexnumber; i++) { if (range != 0) { dice[i - 1] += dicenumber + " "; counter++; if (counter == range) { counter = 0; dicenumber++; } if (i == indexnumber) { range /= 6; = 0; } if (dicenumber == 7) { dicenumber = 1; } } thread.sleep(1); } return dice; } 

the simplest possible way think of:

list<string> dices = new list<string>(); (int = 1; <= 6; i++) { (int j = i; j <= 6; j++) { (int k = j; k <= 6; k++) { dices.add(string.format("{0} {1} {2}", i, j, k)); } } } 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -