Code: Select all
;-------------------------------------------------------------------------------
MultiWordAnagrams(String, SpaceCount) { ; return an array with the sub-keywords
;-------------------------------------------------------------------------------
global Max_Input_Length, DICT
Solutions := Combinations(String, Max_Input_Length)
Keyword := make_Keyword(String) ; String has no spaces!
Len0 := StrLen(String) ; # of letters in String (Input without spaces)
Len1 := (Len0 + 1) // 2 ; # of letters in longer word
Result := [], Previous := []
Loop, % Len0 - Len1 {
Index1 := Len1 + A_Index - 1 ; iterate from e.g. 5 to 8 (for 9 letters)
For Key, Size in Solutions[Index1] {
Compl := Complement(Keyword, Key)
If Not Previous.HasKey(Compl)
And DICT[Size].HasKey(Key)
And DICT[Len0 - Size].HasKey(Compl) {
Previous[Key] := True
For each, Anagram1 in DICT[StrLen(Key), Key]
For each, Anagram2 in DICT[StrLen(Compl), Compl] {
Result.Push(Anagram1 " " Anagram2)
Result.Push(Anagram2 " " Anagram1)
}
}
}
}
Return, Result
}