 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Lone Guest
|
Posted: Sat Sep 06, 2008 3:49 am Post subject: Anagram Bot |
|
|
| How do I make a bot be where you can enter 7 letters, and it will enter the possibilities into the game? |
|
| Back to top |
|
 |
[VxE]
Joined: 07 Oct 2006 Posts: 1496
|
Posted: Sat Sep 06, 2008 4:23 am Post subject: |
|
|
| Code: | InputBox, word, Enter a Word, Enter a series of letters to see all the arrangements of those letters.
msgbox % Permutate(word)
Permutate(set,delimeter="",trim="", presc="")
{ ; function by [VxE], returns a newline-seperated list of
; all unique permutations of the input set.
; 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)
} |
The rest is up to you. _________________ My Home Thread
More Common Answers: [1]. It's in the FAQ [2]. Ternary ( a ? b : c ) guide [3]. Post code inside [code][/code] tags ! |
|
| Back to top |
|
 |
Lone Guest
|
Posted: Sat Sep 06, 2008 4:27 am Post subject: |
|
|
| [VxE] wrote: | | Code: | InputBox, word, Enter a Word, Enter a series of letters to see all the arrangements of those letters.
msgbox % Permutate(word)
Permutate(set,delimeter="",trim="", presc="")
{ ; function by [VxE], returns a newline-seperated list of
; all unique permutations of the input set.
; 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)
} |
The rest is up to you. |
Can you make it where it types them out every two seconds for me?
So like if I had notepad open, it would enter the words 2 seconds apart in there. It would really help me out. |
|
| Back to top |
|
 |
Lone Guest
|
Posted: Sat Sep 06, 2008 4:37 am Post subject: |
|
|
Sorry for double post.
But that gives out the possibilities, I am looking for real words. |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1145 Location: The Interwebs
|
Posted: Sat Sep 06, 2008 4:38 am Post subject: |
|
|
| Lone wrote: | | But that gives out the possibilities, I am looking for real words. |
For that, you would need to have a list of every English word, and then check every produced permutation against that list. _________________ PlayAHK! Try it out  |
|
| Back to top |
|
 |
Lone Guest
|
Posted: Sat Sep 06, 2008 4:40 am Post subject: |
|
|
| Krogdor wrote: | | Lone wrote: | | But that gives out the possibilities, I am looking for real words. |
For that, you would need to have a list of every English word, and then check every produced permutation against that list. |
Could it connect to the site http://www.anagrammer.com/, or http://www.anagramssolved.com/ and check? |
|
| Back to top |
|
 |
Slanter
Joined: 28 May 2008 Posts: 397 Location: Minnesota, USA
|
Posted: Sat Sep 06, 2008 5:09 am Post subject: |
|
|
Try looking at UrlDownloadToFile, and use it with a url like | Code: | | http://www.anagrammer.com/YourWordHere |
_________________ Unless otherwise stated, all code is untested
(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination. |
|
| Back to top |
|
 |
Lone Guest
|
Posted: Sat Sep 06, 2008 5:24 am Post subject: |
|
|
| Slanter wrote: | Try looking at UrlDownloadToFile, and use it with a url like | Code: | | http://www.anagrammer.com/YourWordHere |
|
Ahh I get it. Any tips on going about that? I am just now learning AHK, |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 666 Location: MN, USA
|
|
| Back to top |
|
 |
peterm
Joined: 25 Jul 2006 Posts: 20
|
Posted: Sat Sep 06, 2008 7:21 pm Post subject: |
|
|
The way to do this has ben covered a few times.
You should take the word (or string of characters created from the code on this thread) e.g. CABLE, and convert it to a count of characters e.g. A1B1C1E1L1. There is an excellent function on the forum for this.
Search the forum for a function called Pattern.
You can then look the pattern string A1B1C1E1L1 up in an online dictionary. All words with this pattern are anagrams of the base word. Search the forum for Words.db, this is a text file and can be viewed in a standard text editor.
I have used this method and it works very well.
I might even add you idea to my anagram program.
Peter |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 666 Location: MN, USA
|
Posted: Sat Sep 06, 2008 11:18 pm Post subject: |
|
|
Thanks, peterm. I hadn't seen SKAN's pattern function before... very enlightening, and wow is it fast!
I wish it would also return smaller words that are contained in a group of letters, for playing Scrabble. _________________ http://autohotkey.net/~jaco0646/ |
|
| Back to top |
|
 |
Guest
|
|
| Back to top |
|
 |
Guest
|
Posted: Sun Sep 07, 2008 4:31 am Post subject: |
|
|
| Lone wrote: | | Slanter wrote: | Try looking at UrlDownloadToFile, and use it with a url like | Code: | | http://www.anagrammer.com/YourWordHere |
|
Ahh I get it. Any tips on going about that? I am just now learning AHK, |
How would I make it get it from the site, and only what I want from the site? |
|
| Back to top |
|
 |
Superfraggle
Joined: 02 Nov 2004 Posts: 970 Location: London, UK
|
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 666 Location: MN, USA
|
Posted: Sun Sep 07, 2008 6:40 pm Post subject: |
|
|
I've been examining SKAN's code, and reduced its size quite a bit. | Code: | #SingleInstance force
#NoEnv
SetBatchLines, -1
Gui, Font, s9, Verdana
Gui, Add, Edit, r1 w250 c800000 UpperCase vWord
Gui, Add, Button, ym Default gFetch, Go
Gui, Add, Edit, xm r9 w285 ReadOnly vResults
Gui, Show,,Anagram Finder
return
GuiEscape:
GuiClose:
ExitApp
return
Fetch:
GuiControl,,Results, Searching... please wait.
Gui, Submit, NoHide
pattern := Pattern(Word)
anagrams=
Loop, Read, WORDS.DB
{
StringSplit, split, A_LoopReadLine, =
If (StrLen(pattern) < StrLen(split1))
continue
count := (StrLen(split1)//2)-1
Loop, %count%
If pos := InStr(pattern, SubStr(split1, A_Index*2, 1))
{
If (SubStr(pattern, pos+1, 1) < SubStr(split1, (A_Index*2)+1, 1))
break
Else If (A_Index = count)
anagrams .= split2 "`n"
}
Else break
}
StringReplace, anagrams, anagrams, `,, `n, A
StringLower, anagrams, anagrams
Sort, anagrams
GuiControl,,Results,% anagrams ? anagrams:"No Matches Found."
PostMessage, 0xB1, 0, -1, Edit1, A ;EM_SetSel
return
Pattern(input)
{
Loop, Parse, input
var .= A_LoopField "`n"
Sort, var
Loop, Parse, var
{
StringReplace, input, input, %A_LoopField%,,UseErrorLevel
If ErrorLevel
output .= A_LoopField ErrorLevel
}
Return, "[" output "]"
} | It still uses the WORDS.db file found in the original link, since the word list needs a letter-count format. I'm still trying to find the best way to make it return smaller words contained in larger ones. I've tried a few things, but nothing I'm happy with yet.
EDIT: Thanks to ideas I took from peterm's script, I was able to finish my own. Many thanks in return. The above code has been updated. _________________ http://autohotkey.net/~jaco0646/
Last edited by jaco0646 on Sun Oct 26, 2008 12:24 am; edited 1 time in total |
|
| 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
|