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
https://forums.phpfreaks.com/topic/257180-generating-combinations-from-charset/
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.