# How to list all possible combinations for a predefined set of words?

## Recommended Posts

i need to generate a .txt  list of all possible combinations of a predefined set of words with no word repeated in the same combination

For example, if the words are 1, 2, 3

I'd need the following list:

```1
2
3
12
13
21
23
31
32
123
213
231
132
312
321
```
Edited by aeau2080

##### Share on other sites

Try this, recursive way

It's brute force so good luck

```\$Form1 = GUICreate("Form1", 150, 310, 200, 100)
\$List = GUICtrlCreateList("", 20, 20, 110, 250)
\$label = GUICtrlCreateLabel("", 20, 280, 110, 20)

Global \$text[7] = ["1", "2", "3", "4", "5", "6", "7"], \$n = 0
_LetsGo("")
GUICtrlSetData(\$label, \$n & "  solutions")
SplashOff()
GUISetState()

While GUIGetMsg()<>-3
Wend

Func _LetsGo(\$string)
For \$i = 0 to UBound(\$text)-1
If not Stringinstr(\$string, \$text[\$i]) Then
_LetsGo(\$string & \$text[\$i] )
GUICtrlSetData(\$List, \$string & \$text[\$i] & "|")
\$n += 1
EndIf
Next
EndFunc```
Edited by mikell

##### Share on other sites

what does this do.... it just opens a splash saying loading,,,, i need it to create a txt file with the combinations to use as a dictionary

Edited by aeau2080

##### Share on other sites

There are 13699 possibles combinations... you have to wait a moment before the list is created

This is the engine, it's not so difficult to replace in the script the writing to a list by a writing to a file ^^

##### Share on other sites

i am a n00b, so which part to change?

##### Share on other sites

Here it is... faster without a gui

```Global \$text[7] = ["1", "2", "3", "4", "5", "6", "7"], \$n = 0
\$file = FileOpen(@scriptdir & "\list.txt", 1)
_LetsGo("")
FileClose(\$file)
Exit

Func _LetsGo(\$string)
For \$i = 0 to UBound(\$text)-1
If not Stringinstr(\$string, \$text[\$i]) Then
FileWrite(\$file, \$string & \$text[\$i] & @crlf)
_LetsGo(\$string & \$text[\$i] )
EndIf
Next
EndFunc```

Ok it's sorted now

Edited by mikell

##### Share on other sites

@aeau2080,

What you're after is the list of all permutations of all non-empty subset of a set of 7 elements (the 7 names you used).

It's easy to show that the number of such subsets (without respect to order of their elements) is 2N - 1 for an initial set on N elements, so in your case 27-1 = 127. This is the initial subset count:

7 subsets of length 1

21 subsets of length 2

35 subsets of length 3

35 subsets of length 4

21 subsets of length 5

7 subsets of length 6

1 subsets of length 7

Note: the values 1 - 7 - 21 - 35 - 35 - 21 - 7 -1 is the 7th row of the Pascal triangle (giving binomial coefficients).

Then you have to enumerate the permutations of these subsets. For each subset of length N there are N! permutations. Hence the actual count of all the list you want to try is:

1 * 7 lists of length 1 = 7

2 * 21 lists of length 2 = 42

3*2 * 35 lists of length 3 = 210

4*3*2 * 35 lists of length 4 = 840

5*4*3*2 * 21 lists of length 5 = 2520

6*5*4*3*2 * 7 lists of length 6 = 5040

7*6*5*4*3*2 * 1 lists of length 7 = 5040

As Mikell said, this is a big total of 13699 lists each comprising 1 to 7 names, so it is little surprise that it takes some time to build.

You can also combine the actions of _ArrayCombinations() then _ArrayPermute() on every result (after removing the 0-th element).

The number of lists explodes rapidly. This is that integer sequence.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

##### Share on other sites

We don't need to provide brute force cracking methods for anyone.

Edit:

Permutations are one thing when you can only speculate the use, here there was no denying the usage which is why I warned and closed this thread.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites
This topic is now closed to further replies.

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...