 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Murp|e
Joined: 12 Jan 2007 Posts: 531 Location: Norway
|
Posted: Wed Jan 06, 2010 1:21 pm Post subject: All possible combinations of letters |
|
|
I want to find all possible combinations of letters and digits restricted to a given length. The results of a simplified example using the letters "abc" and restricted to a length of 2 would be:
| Quote: | AA
AA
AB
AC
BA
BB
BC
CA
CB
CC
|
I started to adapt this script of Zed Gecko:
| Code: | SetBatchlines -1
#NoEnv
loop, 3 ;26 chars + 9 digits
{
AsciNum := A_Index + 64 ;48
if (AsciNum > 57 and AsciNum < 65)
continue
baselist .= Chr(AsciNum)
}
new_newlist := makelists(baselist, "")
MsgBox %list_idx% strings created:`n`n%FinalList%
;fileappend, %FinalList%, permutations.txt
Return
makelists(baselist, newlist)
{
loop, parse, baselist
{
global rec_depth
thischar := A_Loopfield
StringReplace, newbaselist, baselist, %thischar%,, All
new_newlist := newlist . thischar
if (newbaselist = "")
{
rec_depth := 0
Tooltip, %rec_depth%, 0, 40, 2
newlist(new_newlist)
}
else
{
rec_depth ++
Tooltip, %rec_depth%, 0, 40, 2
makelists(newbaselist, new_newlist)
}
}
return new_newlist
}
newlist(newlist)
{
global FinalList
global list_idx
SetFormat, float, 3.0
list_idx ++
FinalList := FinalList . "`n" . newlist
tooltip %list_idx%, 0, 0, 1
return
} |
which can produce this kind of list:
| Quote: | ABC
ACB
BAC
BCA
CAB
CBA
|
But I'm lost as to what to do next:
1. I have no idea how to implement a restriction on the total length of the string.
2. I have no idea how to specify that the same letters can occur multiple times in the string.
3. I have used, but never written recursive functions before. Where to start?
I wanted to see if it was possible to write a script which would use the above mentioned functions together with URLDownloadToVar to find available and short domain names in certain country domains (Such as .no, .ca etc.).
If URLDownloadToVar returns 0, the script would assume the domain is available. Although this is probably not a sure-fire solution, it avoids (mis)use of online domain whois database. |
|
| Back to top |
|
 |
SoLong&Thx4AllTheFish
Joined: 27 May 2007 Posts: 4999
|
|
| Back to top |
|
 |
peterm
Joined: 25 Jul 2006 Posts: 51
|
Posted: Wed Jan 06, 2010 8:17 pm Post subject: |
|
|
There was some nice code written by VxE that is recursive.
| Code: | ; Permutate -------------------------------
; creates a list of permutations from word
Permutate(set,delimeter="",trim="", presc="")
{ ; function by [VxE]
; returns a newline-seperated list of all
; unique permutations of the input set.
; set = word to be worked on
; delimiter can be used to provide a list of words
; trim is for trimming characters out of the word
; presc = use unknown
; Note that the length of the list will be (N!)
d := SubStr(delimeter,1,1)
StringSplit, m, set, %d%, %trim%
IfEqual, m0, 1, return m1 d presc
Loop %m0%
{
remains := m1
Loop % m0-2
x := A_Index + 1, remains .= d m%x%
list .= Permutate(remains, d, trim, m%m0% d presc)"`n"
mx := m1
Loop % m0-1
x := A_Index + 1, m%A_Index% := m%x%
m%m0% := mx
}
return substr(list, 1, -1)
}
|
|
|
| Back to top |
|
 |
Murp|e
Joined: 12 Jan 2007 Posts: 531 Location: Norway
|
Posted: Wed Jan 06, 2010 10:28 pm Post subject: |
|
|
Thanks guys, but all three scripts (Zed Gecko, Evan and VxE) seem to do the same thing, namely find all permutations of a string. This is good and well, but I'm no closer to solving my script or learning about recursion in AHK. Perhaps all of this is simply above me.
hugov: I'm painstakingly aware of the slim pickings in short domain names, that's precisely why I need this kind of script to increase the odds of finding something I can use. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|