Your question, your audience. Choose who sees your identityâ€”and your questionâ€”with question security.

I need C# example how to make permutation without repetition like:

Variations of {1 2 3} choose 2:**RESULT **{1 2}, {1 3}, {2 3}

{1 1}, {2, 2} ->not allowed

{1 2} = {2 1}

Variations of {1 2 3} choose 2:

{1 1}, {2, 2} ->not allowed

{1 2} = {2 1}

```
for(int x = 0; x < <your array>.length; x++)
{
for(int y = 0; y < <your arracy.length; y++)
{
if(x==y) continue;
<output your permutations here>
console.print(string.format("[ {0} {1} ]", x, y));
}
}
```

http://msdn.microsoft.com/en-us/library/bb348436(v=vs.110).aspx

I know that this case have 210 combinatins counting based on this formula ( 10!/(6!*(10-6)!), but ! need list of all combinations

int[] array = new [] {1,2,3,4,5,6,7,8,9,10}

Results will be:

1. {1, 2, 3, 4, 5, 6}

2. {2, 3, 4, 5, 6, 7}

3. {3, 4, 5, 6, 7, 8}

.

.

.

So it would look like

1,2,3,4,5,6

1,2,3,4,5,7

1,2,3,4,5,8

1,2,3,4,5,9

1,2,3,4,5,10 <-- hit the max

1,2,3,4,6,7 <--- 5 goes to 6, then reset last to 7

This can also be modeled in binary

1111110000 represents 1,2,3,4,5,6

1111101000 represents 1,2,3,4,5,7

Move the rightmost 1 one space to the right, if it is at the end, move the next one

So something like

1101100011 would change to

1101011100

TommySzalapski, I made small modification for C# and works perfect for number from 1 to 10, I've got result with 210 combinations.

The problem is that solution is not applicable for any ten numbers, like

int[] array = new int[] { 33, 23, 45, 6, 3, 2, 1, 15, 14, 11 } and now try find all six number combination form array.

1. {33, 23, 45, 6, 3, 2}

2. {33, 23, 45, 6, 3, 1}

For example

int[] data_array = new int[] { 33, 23, 45, 6, 3, 2, 1, 15, 14, 11 }

Then change the output array logic to

```
for(int i = 0; i < SIZE; ++i)
print_to_screen(data_array[array[i]-1]);
```

The -1 is because we started from 1 in array. If you modified it to use 0-9 instead of 1-10, then you could skip the -1.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

Open in new window