Name generator AKA brute force algorithm?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tempuser
Posts: 12
Joined: 30 Jan 2018, 17:37

Name generator AKA brute force algorithm?

21 Oct 2018, 04:40

Can anyone help me with changing my code to work with any string length (defined by iNameLenght) without copy/pasting loop, parse section (and without using functions if possible - but not necessary)?

Code: Select all

;alfabet := "abcdefghijklmnopqrstuvwxyz0123456789"
alfabet := "abcdefghijklmnopqrstuvwxyz"
iNameLenght := 4

loop, parse, alfabet
{
	l1 := A_LoopField
	loop, parse, alfabet
	{
		l2 := A_LoopField
		loop, parse, alfabet
		{
			l3 := A_LoopField
			loop, parse, alfabet
			{
				l4 := A_LoopField
				sName := l1 . l2 . l3 . l4 . ","
				sAllNames := sAllNames . sName
			}
		}
	}
}
MsgBox, %sAllNames%
eqv
Posts: 72
Joined: 18 Sep 2018, 22:17

Re: Name generator AKA brute force algorithm?

22 Oct 2018, 21:27

tempuser wrote:
21 Oct 2018, 04:40
Can anyone help me with changing my code to work with any string length (defined by iNameLenght) without copy/pasting loop, parse section (and without using functions if possible - but not necessary)?
"While", "While" everywhere:

Code: Select all

a := "abcde"	;; character's used
b := 4		;; lenght

d:=f:=0, c:=[], e:=[], g:=[]
While !(subStr(a,a_index,1)="")
g[a_index]:=subStr(a,a_index,1)
While !(g[a_index]="")
c[a_index] := g[a_index]

While !(b=a_index) {
While !(c[d+1]="") {
d++
While !(g[a_index]="")
f++, e[f] := c[d] . g[a_index]
} d:=f:=0
While !(e[a_index]="")
c[a_index] := e[a_index]
}

While !(c[a_index-1]=""&&a_index<>1)
z .= c[a_index] . " "
Msgbox % z

/*
While !(c[a_index-1]=""&&a_index<>1)
Msgbox % c[a_index]
*/
Edit: Way more efficient code ↓.

Code: Select all

a := "0123456789"	;; character's used
b := 5			;; lenght

Loop, % (StrLen(a), f:=[])
f[A_Index]:=SubStr(a,A_Index,1)

Loop, % (b-1, c:=[f*])
{
	For b, d In (c, e:=[])
	{
		For b, g In f
		e[e.Length()+1]:=d g
	} c:=[e*]
}

For b, a In c
c .= a " "
Msgbox % c



/*
===================================
[g]	CharactersArray
[c`d]	AcumArray ` (=AcumArray.Length)
[e]	TempArray
-------------------------------------------------
Example::
AcumArray      |      CharactersArray	= TempArray[result]
00	         |	1		= 001
	         |	2		= 002
	         |	3		= 003
01	         |	1		= 011
	         |	2		= 012
	         |	3		= 013
02	         |	1		= 021
	         |	2		= 022
	         |	3		= 023
...	         |	...		= ...
-------------------------------------------------
Note: For each "loop" use "force-expression" to save some lines.
*/
Last edited by eqv on 29 Dec 2018, 18:45, edited 6 times in total.
tempuser
Posts: 12
Joined: 30 Jan 2018, 17:37

Re: Name generator AKA brute force algorithm?

22 Oct 2018, 22:52

:shock:
It will take few days for me to analyze this code.

Maybe my guideline to avoid to using functions for recurrence was very bad idea... :think:
Because this code looks very complicated for me - but I'm basic coder.

Thanks!
I'll dig into it.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Mannaia666, ntepa and 226 guests