You are not logged in.

- Topics: Active | Unanswered

**Eliatamby****Member**- Registered: 2005-05-06
- Posts: 80

Hi,

I'm just learning C now and am trying to get my head around this permutation pickle I'm in. I can pretty simply write code that will give all permutations of N number of letters from A-z. E.g., if N = 4, it will print out AAAA AAAB .... zzzz. This is pretty simple iteratively or recursively with a counter.

now, however, I want to enter in a string that does not neccessary contain letters in sequence, and find all the possible relevant permutations of that string. E.g. I input a string of BEHP, and I want to find all the permutations of this combination. I don't want BBBB, BBBE, etc., I want BEHP, BHPE, BPHE, etc.

I think my current approach is severely limited by the counter method, as it's giving permutations that are just not relevant.

Also, can someone please confirm the maths on this. If I have a string of 3 letters, ABC, the number of possible combinations is 3! right? 3 factorial?

Thanks

Offline

**elasticdog****Member**- From: Washington, USA
- Registered: 2005-05-02
- Posts: 995
- Website

I don't know C, but have a couple of logic-based suggestions. I believe you are right in your permutations calculation of 3!. To solve your problem of combinations, could you do something like put each character into an array (which is ordered by index) and then use a similar technique to the one you used for the other set of letters but base it on the index number?

Offline

**Eliatamby****Member**- Registered: 2005-05-06
- Posts: 80

Thanks elastic, I think that will work PERFECTLY!

Man, I've got to get used to thinking like a programmer.

Offline