0

Possible Duplicate:
Combination Generator in Linq

I am looking of an algorithm (using C#) that can
find all the combinations of specified numbers.
Example:
Numbers:
1 2 3
Combinations:
1
2
3
12
13
21
23
31
32
123
132
213
231
312
321

Only rule: No repetitions of numbers

I have looked around Google, Stackoverflow, as well as numerous other sites.
I would list some of my code, but I have had no success getting anything to work along the right lines.

EDIT: The intention of this is using the generated numbers as the positions of characters in a word. I am creating a word finder, so basically this is what it is being used for:

Program generates:
0
1
01
10

From numbers: 0 1

The program got the numbers 0 and 1 from the user inputting for instance "no".

Example code:
string input = Console.ReadLine();
int size = input.Length; //This is where the 0 and 1 come from

Therefore the different combinations would rearrange the letters, using the length of the inputted word as the base, then comparing it to a word list, I could find existing words.

Community
  • 1
  • 1
Paul
  • 25
  • 1
  • 6
  • You should still post your code and ask specific questions. SO likes to see _some_ effort in the question asker's part. – Jay Riggs Jul 13 '12 at 05:37
  • I noted No repetitions. The link given is something different – Paul Jul 13 '12 at 05:42
  • Nothing that I have made so far has done any good for this question. If I find something that can benefit this then I will post it. – Paul Jul 13 '12 at 05:45

2 Answers2

1

What you really need is a proper utilization of recursion. I think Permutations in C# Using Recursion is exactly what you are looking for.

atiyar
  • 7,762
  • 6
  • 34
  • 75
-1

I'll do more research as I have time and try to improve my answer.

Your program is dealing with combinatorial math (which you can google and read about). There is a formula for calculating your answer. Your question falls under the "Pick x from n" variety with respect to order.

Emily
  • 444
  • 1
  • 3
  • 12