AnsweredAssumed Answered

Create vars containing all possible input combinations

Question asked by triac on Aug 17, 2018
Latest reply on Aug 18, 2018 by fmpdude

Racking my brain over this one portion of a larger word game solver system.

Utilizing a script, possibly in combination with a recursive custom function (minding the 50k limit): the desired output is a set of enumerated variables, each one containing a unique combination of characters, with no two variables containing the same combination of characters, and based only upon the input character supplied. The input would be a single variable, which contains a string of two or more characters (and no spaces).

 

For example:

Example Input = "ABC"

Output =

$word1 = "ABC"

$word2 = "ACB"

$word3 = "BAC"

$word4 = "BCA"

$word5 = "CBA"

$word6 = "CAB"

... ...

Until all possible combinations have been assigned to $word(x). Yes, I understand this can get into the millions, with longer inputs - thus a CF may not necessarily help (or the data might have to somehow be first broken into smaller chunks..) Probably just straight scripting would be the best way to go?

 

So far, I have a basic starter script which dynamically parses out the input into variables with dynamically enumerated variable names - which may or may not be the right direction to take. It does this:

Example Input = "AQPW"

Output =

$letter1 = "A"

$letter2 = "Q"

$letter3 = "P"

$letter4 = "W"

...

And for longer inputs, it keeps creating more variables with enumerated variable names.

 

Now, I need to combine the values that each of those variable contains, into all possible combinations, sans dupes. The order is not important.

Any direction would be appreciated.

Outcomes