This script takes about five second to load (not measured accurately, though). The results are then displayed immediately.
Code: Select all
;-------------------------------------------------------------------------------
; Anagrams.ahk
; by wolf_II
;-------------------------------------------------------------------------------
; simple Anagram searcher
; written with massive help by Helgef from AHK forum
; https://autohotkey.com/boards/viewtopic.php?p=158284#p158284
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
AutoExecute: ; auto-execute section of the script
;-------------------------------------------------------------------------------
#NoEnv ; don't check empty variables
#SingleInstance, Force ; kill old instance
;---------------------------------------------------------------------------
SetBatchLines, -1 ; run script at maximum speed
;===========================================================================
SetWorkingDir, %A_ScriptDir% ; consistent directory
SplitPath, A_ScriptName,,,, AppName ; get AppName from file name
;---------------------------------------------------------------------------
Version := "1.05"
;===========================================================================
; GUI
Gui, New, -MinimizeBox, %AppName% v%Version%
Gui, Add, Edit, w100 vWord gCountLetters Disabled, Loading ...
Gui, Add, Button, x+m yp-1 wp Default Disabled, get Anagrams
Gui, Add, ListBox, xm r10 w210 vLBox
Gui, Add, StatusBar
SB_SetParts(60)
SB_SetText("Length:", 1)
SB_SetText("Count:", 2)
Gui, Show
; https://raw.githubusercontent.com/dwyl/english-words/master/words_alpha.txt
FileRead, Dictionary, words_alpha.txt
DICT := []
Loop, Parse, Dictionary, `n, `r
{
WordLength := StrLen(A_LoopField)
If Not IsObject(DICT[WordLength])
DICT[WordLength] := []
StringLower, Keyword, A_LoopField
Keyword := make_Keyword(Keyword)
If Not IsObject(DICT[WordLength, Keyword])
DICT[WordLength, Keyword] := []
DICT[WordLength, Keyword].Push(A_LoopField)
}
GuiControl, Enable, Word
GuiControl,, Word
GuiControl, Focus, Word
GuiControl, Enable, Button1
Return ; end of auto-execute section
GuiClose:
ExitApp
;-------------------------------------------------------------------------------
CountLetters: ; live display
;-------------------------------------------------------------------------------
GuiControlGet, Word
SB_SetText("Length: " WordLength := StrLen(Word), 1)
Return
;-------------------------------------------------------------------------------
ButtonGetAnagrams: ; display all anagrams of Word found in Dictionary
;-------------------------------------------------------------------------------
GuiControl, Focus, Word
GuiControl, Disable, Button1
GuiControl,, LBox, |
SB_SetText("Count:", 2)
Keyword := make_Keyword(Word), WordList := "", Count := 0
For each, Anagram in DICT[WordLength, Keyword]
WordList .= WordList ? "|" Anagram : Anagram, Count++
GuiControl,, LBox, % WordList ? WordList : "no anagrams for " Word
SB_SetText("Count: " Count, 2)
GuiControl, Enable, Button1
Return
;-------------------------------------------------------------------------------
make_Keyword(Word) { ; return a sorted, comma separated string of chars
;-------------------------------------------------------------------------------
Keyword := LTrim(RegExReplace(Word, "(.)", ",$1"), ",")
Sort, Keyword, D,
Return, Keyword
}
/*--------- end of file --------------------------------------------------------