- Simple code
- Fast loading
- Low memory usage
- Speed for longer inputs
- Esc - Stop search
- ^Esc - Exit App
- Up - Decrease anagrams output length by 1
- Down - Increase anagrams output length by 1 (last is "All")
- PgUp - Decrease anagrams output length by 5
- PgDn - Increase anagrams output length by 5 (last is "All")
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetBatchLines, -1
Gui -DPIScale
Gui, Font,, Consolas
Gui Add, Edit, x15 w455 vaInput gFirstAnagram
GuiControl, Focus, aInput
Gui Add, Text, x15 ym+38 w380 vaInfo, Loading Words...
Gui, Add, ComboBox, x410 ym+32 w60 r25 vaLen gComboAnagram ; AltSubmit
Gui Add, Edit, x15 yp+30 w455 r20 vaOutput
Gui show,, Anagram Cracker
FileRead, wl, Words.txt
loop, Parse, wl, `n, `r
(l:= StrLen(A_LoopField))? (WordsLen_%l%.= A_LoopField "`n", mLen<l? mLen:=l: ""): ""
wl:= l:= ""
GuiControl,, aInfo, Ready!
Return
FirstAnagram:
SetTimer, Execute, -0
Return
Execute:
Gui Submit, NoHide
aEditInput:= 1, aLen:= StrLen(aInput)
Goto Search
ComboAnagram:
;br:= 1
SetTimer, Execute2, -0
Return
Execute2:
Gui Submit, NoHide
Search:
s:= A_TickCount, aLengths:= "", frSp:= SubStr(" ", Strlen(StrLen(aInput))), toLett:= toLettLIn:= ""
GuiControl,, aInfo, % "Input Len.: " StrLen(aInput) frSp "Anag. Found: ... Time: ..."
GuiControl,, aOutPut
Loop Parse, aInput
InStr(toLettLin, A_LoopField)? "": toLettLin.= A_LoopField
Bin:= "", st:= 0, lett:= {}, p:= 1
loop Parse, toLettLin
StrReplace(aInput, A_LoopField, A_LoopField, cnt), lett[A_LoopField]:= cnt
if (aEditInput, ml:=aLen>mLen? mLen: aLen) {
Loop, % (ml, aEditInput:="")
aLengths .= "|" A_Index, (A_Index=ml? aLengths.= "||All": "")
GuiControl,, aLen, % aLengths
} GuiControlGet, ns,, aLen
if (ns="All")
loop, % mLen
aInd:= mLen-(A_Index-1), tl.= WordsLen_%aInd% ; assigning to wl (not cleared before) isn't significantly faster
else tl:= WordsLen_%ns%
while (p:= RegExMatch(tl, "i`am)^[" toLettLin "]+$", m, p+StrLen(m))) {
for i, j in % lett {
StrReplace(m, i, i, cnt)
if (cnt>jj:=j)
Break
} cnt>jj? "": (Bin.= m "`n", st++)
if Br
Break
} Br:= ""
GuiControl,, aOutPut, % (Bin, tl:="")
frSp:= SubStr(" ", Strlen(StrLen(aInput))), seSp:= SubStr(" ", StrLen(st))
GuiControl,, aInfo
, % "Input Len.: " StrLen(aInput) frSp "Anag. Found: " st seSp "Time: " Round((A_TickCount-s)/1000, 2) "s"
Return
#IfWinActive, Anagram Cracker
Up::
GuiControlGet, cF, Focus
if cf=Edit1
ControlSend, Edit2, {Up}, Anagram Cracker
Else Send {Up}
Return
Down::
GuiControlGet, cF, Focus
if cf=Edit1
ControlSend, Edit2, {Down}, Anagram Cracker
Else Send {Down}
Return
PgUp::
GuiControlGet, cF, Focus
if cf=Edit1
ControlSend, Edit2, {Up 5}, Anagram Cracker
Else Send {PgUp}
Return
PgDn::
GuiControlGet, cF, Focus
if cf=Edit1
ControlSend, Edit2, {Down 5}, Anagram Cracker
Else Send {PgDn}
Return
^Esc::
GuiClose:
ExitApp
Esc:: br:= 1
The hardest task is to retrieve words having each character only once.
Input word1: abcdefghijklmnopqrstuvwxyz'
Input word2: abcdefghijklmnopqrstuvwxyzéóçíáèêüäîïâåöûñôëàøúÅÖÜ' (depends on your word list)