Jump to content
Sign in to follow this  
hugo321

letters and combinations

Recommended Posts

hugo321

so, i want to make a program in which i input letters. 5-7 letters or so, and i want my program to make all possible combinations of the letters, is this possible with autoit?

then i want it to filter out words which i have in a text document list.

would this be the best way to go around this?

i have a list of words. > i input letters > program makes all possible words made from the letters.

would this be a complex task to do? i kinda need some pointers here ;)

Share this post


Link to post
Share on other sites
weaponx

Are partial word matches allowed? Sounds like a Scrabble word generator.

Edited by weaponx

Share this post


Link to post
Share on other sites
hugo321

Are partial word matches allowed? Sounds like a Scrabble word generator.

yea... im going to cheat in scrabble... ;) no really, it is a challenge, and i really have no clue in where to start in the generation part, cause making a program make ALL combinations of a few letters or numbers is kindof hard for me to understand.

i could make alot with the random line, but that would make dublicates and a non logic list. if it was numbers i would like them to be 1,2,3,4,5 and letters alike.

Share this post


Link to post
Share on other sites
weaponx

Now i'm more confused. From your first post this is what I got.

You have a list of valid dictionary words. You want to input some letters and retrieve every word from your "dictionary" containing these letters.

How do numbers fit into that?

Share this post


Link to post
Share on other sites
wakummaci

I think he just said an example of what he wants.

Share this post


Link to post
Share on other sites
weaponx

This will search every word in an array and output *only* words containing ALL of the given letters.

I had no luck with the regular expression method since their is no AND operator in regex.

;Characters used to find matching words (order doesn't matter)
$string = "cp"

Dim $array[9]
$array[0] = "apple"
$array[1] = "appliance"
$array[2] = "application"
$array[3] = "beast"
$array[4] = "berry"
$array[5] = "boat"
$array[6] = "cantaloupe"
$array[7] = "cargo"
$array[8] = "collision"

For $X = 0 to Ubound($array) -1
    ;METHOD 1 - Regular Expression
    ;$result = StringRegExp($array[$X],".*[c].*\A.*[s].*",0)
    
    ;METHOD 2 - Loop through every character
    $result = 1
    $chars = StringSplit($string,"")
    For $Y = 1 to $chars[0]
        
        If NOT StringInStr($array[$X], $chars[$Y]) Then 
            ContinueLoop 2
        EndIf
    Next
    
    ;Output matched word
    If $result Then ConsoleWrite($array[$X] & @CRLF)
Next

Share this post


Link to post
Share on other sites
martin

This will search every word in an array and output *only* words containing ALL of the given letters.

I had no luck with the regular expression method since their is no AND operator in regex.

;Characters used to find matching words (order doesn't matter)
$string = "cp"

Dim $array[9]
$array[0] = "apple"
$array[1] = "appliance"
$array[2] = "application"
$array[3] = "beast"
$array[4] = "berry"
$array[5] = "boat"
$array[6] = "cantaloupe"
$array[7] = "cargo"
$array[8] = "collision"

For $X = 0 to Ubound($array) -1
    ;METHOD 1 - Regular Expression
    ;$result = StringRegExp($array[$X],".*[c].*\A.*[s].*",0)
    
    ;METHOD 2 - Loop through every character
    $result = 1
    $chars = StringSplit($string,"")
    For $Y = 1 to $chars[0]
        
        If NOT StringInStr($array[$X], $chars[$Y]) Then 
            ContinueLoop 2
        EndIf
    Next
    
    ;Output matched word
    If $result Then ConsoleWrite($array[$X] & @CRLF)
Next
That finds all the words which contain at least one of each of the different letters in $string. It won't find words which only consist of all the letters in $string. If that is what is wanted here is one way to do it

#include <Array.au3>

;Characters used to find matching words (order doesn't matter)
$string = "lpeap"

Dim $array[9]
$array[0] = "apple"
$array[1] = "appliance"
$array[2] = "application"
$array[3] = "beast"
$array[4] = "berry"
$array[5] = "boat"
$array[6] = "cantaloupe"
$array[7] = "cargo"
$array[8] = "collision"

$sort1 = Ordered($string);Put $string into alphabetical order.
For $X = 0 To UBound($array) - 1
     ;find only words which have exactly the same letters as in $string
    If $sort1 = Ordered($array[$X]) Then ConsoleWrite($array[$X] & @CRLF)
Next



;func to return the string arranged alphabetically
Func Ordered($ss)
    Local $res, $n
    Local $aS = StringSplit($ss, "")
    _ArraySort($aS)
    For $n = 1 To UBound($aS) - 1
        $res &= $aS[$n]
    Next
    Return $res
EndFunc ;==>Ordered
Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
weaponx

That finds all the words which contain at least one of each of the different letters in $string. It won't find words which only consist of all the letters in $string. If that is what is wanted here is one way to do it

You are incorrect. Continueloop is called if even one letter isn't matched in a word, moving to the next word in the dictionary.

Share this post


Link to post
Share on other sites
martin

You are incorrect. Continueloop is called if even one letter isn't matched in a word, moving to the next word in the dictionary.

I didn't mean that weaponex. I meant that your script checks if the letters in $string are in the string in each array. But if $string has the letter B twice and the string in the array has only 1 it will say it matched, and if the string in the array has letters which are not in $string it will also say it matched. So my script was to match only those words in the array which had exactly the same letters as in string, or another words, my script only matches anagrams.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.