Jump to content

Generating combinations from charset


silkfire

Recommended Posts

I searched online and seen some complex c and c# code which I didn't understand much of. But how do I generate an array with all string combinations based on length and from a charset?

 

E.g. charset = {'a', 'b', 'c'}

 

Length = 2.

 

Then it should generate first all 1-char strings:

 

a

b

c

 

Then all 2-char strings:

 

aa

ab

ac

ba

bb

bc

ca

cb

cc

 

And then all added to the same array.

 

I think there's some way of doing it with recursion but to me it's like thinking with a 4th dimension my mind can't grasp this logic! :D

Link to comment
Share on other sites

There have been numerous posts on this forum in the past for similar things. But, if you are planning to do this with anything more than a small subset of characters and character count it is not realistic. The permutations will expand exponentially.

 

Here are a few related posts:

http://www.phpfreaks.com/forums/index.php?topic=346630.0

http://www.phpfreaks.com/forums/index.php?topic=298656.0

http://www.phpfreaks.com/forums/index.php?topic=135633.0

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.