Mikon Posted July 12, 2006 Share Posted July 12, 2006 (edited) well... i dont really know how to explain what this function does but i will try this function generates all possible combinations for a string.. i think i should just give an example: if you put in "ab" then it will return an array containing: the number of combinations (in this case 6) a b aa ab ba bb (of course you can do this with numbers or other letters too) whatever, heres the UDF Func GetCombinations($sString) Local $aString = StringSplit($sString, "") Local $iPossibilities = 0 Local $k For $k = 1 To $aString[0] $iPossibilities += $aString[0] ^ $k Next Local $aReturn[$iPossibilities + 1] = [$iPossibilities] Local $i = 0 Local $LastString = "" Local $CalcBack = 1 While $i < $aReturn[0] If $CalcBack > 1 Then $LastString = $aReturn[$i + 1 - $CalcBack] EndIf For $j = 1 To $aString[0] $aReturn[$i + $j] = $LastString & $aString[$j] Next $CalcBack += $aString[0] - 1 $i += $aString[0] WEnd Return $aReturn EndFunc calling the following will print the same example as above but in a messagebox Func Print($String) Local $a = GetCombinations($String) Local $i Local $s = "" For $i = 1 To $a[0] $s &= $a[$i] & @CRLF Next MsgBox(0, $a[0], $s) EndFunc Print("ab") sadly the maximum length of your inputstring is 7 letters because the function saves the combinations in an arrays and the arraysize is limited (7 letters produce 960799 combintaions!) so this is just usefull for learning something about arrays and... logic hope you like it, Mikon Edited July 12, 2006 by Mikon Link to comment Share on other sites More sharing options...
Paulie Posted July 12, 2006 Share Posted July 12, 2006 Nice! this is fun, but 2 things i'd sugest trying to do 1- make the fist space of the array contain the total number of combonations, so if thats all you wanted, and not an example of each, it would be easily accessable 2- Get rid of the limit if you can, i want to try 123456789, but it wont let me Link to comment Share on other sites More sharing options...
cppman Posted July 12, 2006 Share Posted July 12, 2006 (edited) nice! Now I can correctly do the math for my GUID GENERATOR function This is a nice function, and will come very handy. @Paulie > just do... scratch what i wrote, after looking at some numbers i relized i suck at math. lol. btw, I love your personal message(the text or whatever under your avatar). Edited July 12, 2006 by CHRIS95219 Miva OS Project Link to comment Share on other sites More sharing options...
Xenobiologist Posted July 12, 2006 Share Posted July 12, 2006 HI, you can change this way. #include<Array.au3> Print("ab") Func Print($String) Local $a = GetCombinations($String) _ArrayDisplay($a, "Combinations") EndFunc Func GetCombinations($sString) Local $aString = StringSplit($sString, '') Local $iPossibilities = 0 For $k = 1 To $aString[0] $iPossibilities += $aString[0] ^ $k Next Local $aReturn[$iPossibilities + 1] = [$iPossibilities] Local $LastString = '' Local $CalcBack = 1 Local $i = 0 While $i < $aReturn[0] If $CalcBack > 1 Then $LastString = $aReturn[$i + 1 - $CalcBack] EndIf For $j = 1 To $aString[0] $aReturn[$i + $j] = $LastString & $aString[$j] Next $CalcBack += $aString[0] - 1 $i += $aString[0] WEnd Return $aReturn EndFunc So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
RazerM Posted July 12, 2006 Share Posted July 12, 2006 Someone made a Permutate function before where for 123 it gave out 123 132 213 231 312 321 I remember trying it for 123456789 and it took bloody ages In your UDF you should use _ArrayAdd to remove the limit My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop. Link to comment Share on other sites More sharing options...
Mikon Posted July 12, 2006 Author Share Posted July 12, 2006 i dont think _ArrayAdd can increase the possible size of an array. it just "Adds a specified value at the end of an array, returning the adjusted array." so this probably wont help Mikon Link to comment Share on other sites More sharing options...
RazerM Posted July 12, 2006 Share Posted July 12, 2006 Oh i get you now, I was thinking that you had hardcoded the array size. It was yesterday I looked at the code. Sorry My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now