anystupidassname Posted August 20, 2005 Share Posted August 20, 2005 I've been unable to find such a tool online but it shouldn't be too difficult with AutoIt. I want to a make a tool that writes all permutations possible from a combination of numbers and/or letters to a file. So it would ask the length/number of characters in the output and what number(s) and letter(s) to use and then write all permutations to a file. Getting the input and writing the output is easy, I can do that. I'm not sure how to go about the calculations to generate the output. Ideas greatly appreciated. This signature is computer generated, nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#....... Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 20, 2005 Moderators Share Posted August 20, 2005 (edited) I've been unable to find such a tool online but it shouldn't be too difficult with AutoIt. I want to a make a tool that writes all permutations possible from a combination of numbers and/or letters to a file. So it would ask the length/number of characters in the output and what number(s) and letter(s) to use and then write all permutations to a file.Getting the input and writing the output is easy, I can do that. I'm not sure how to go about the calculations to generate the output. Ideas greatly appreciated.<{POST_SNAPBACK}>Dev\Null Wrote this: Permutation Edited August 20, 2005 by ronsrules Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
anystupidassname Posted August 21, 2005 Author Share Posted August 21, 2005 Dev\Null Wrote this: Permutation<{POST_SNAPBACK}>Thank you. That is quite useful but I'm afraid I don't understand the uncommented code enough to modify it for my needs. I need to permutate "dynamically" if you will, not statically like dev/null/ s code does. In other words, feed it what characters to permutate and how many digits or characters the output should be. This signature is computer generated, nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#....... Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 21, 2005 Moderators Share Posted August 21, 2005 (edited) In other words, feed it what characters to permutate and how many digits or characters the output should be.I might not be understanding? But this is an example of just stringing left as many as the Output you choose.$permutarray = permute("1234")expandcollapse popup#include <string.au3> #include <array.au3> $Digits = InputBox("Permutation", "Enter Digits", "", "", 80, 80) $Output = InputBox("Permutation", "OutPut Number", "", "", 80, 80) $permutarray = permute($Digits) $msg = "" for $n = 1 to $permutarray[0] $pString = StringLeft($permutarray[$n], $Output) $msg = $msg & $pString & @CRLf next msgbox(0,"", $msg) func rotate($sString, $nRotateLevel) local $aStringArray = StringSplit($sString,"") local $nStartRotate = $aStringArray[0] - $nRotateLevel + 1 local $n, $tempchar, $tempstr = "", $retval = "" for $n = 1 to $nStartRotate - 1 $tempstr= $tempstr & $aStringArray[$n] next $tempchar = $aStringArray[$nStartRotate] for $n = $nStartRotate+1 to $aStringArray[0] $retval = $retval & $aStringArray[$n] next $retval = $tempstr & $retval & $tempchar return $retval endfunc func permute_internal($sString, $nRotateLevel, byref $permutations) local $n, $str dim $arr[$nRotateLevel] if $nRotateLevel = 2 then $permutations = $permutations & ":" & rotate($sString,$nRotateLevel) return endif $str = $sString for $n = 0 to $nRotateLevel -1 $str = rotate($str,$nRotateLevel) $arr[$n] = $str ;--- special check, to stop a level beeing printed twice --- if not (($n = 0) AND (StringLen($sString) > $nRotateLevel)) then $permutations = $permutations & ":" & $arr[$n] endif permute_internal($arr[$n],$nRotateLevel-1,$permutations) next endfunc func permute($sString) global $permutations = "" permute_internal($sString,StringLen($sString),$permutations) $permutations = StringTrimLeft($permutations,1) return StringSplit($permutations,":") endfuncEdit: Forgot an EndFunc Edited August 21, 2005 by ronsrules Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
anystupidassname Posted August 21, 2005 Author Share Posted August 21, 2005 (edited) Lets say for example I want it to permutate 0123456789wtf as many times as possible in a 3 character string without repeating. 012 123 234 345 456 567 678 789 89w 9wt wtf 111 112 113 124 125 126 and the list goes on Edited August 21, 2005 by anystupidassname This signature is computer generated, nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#....... Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 21, 2005 Moderators Share Posted August 21, 2005 Err that seems it would take a very very long time Would be nice for myself to see if there is a quicker method. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 21, 2005 Moderators Share Posted August 21, 2005 Guess it would of helped if I tested my own script to see if it had duplicates... sorry. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
/dev/null Posted August 21, 2005 Share Posted August 21, 2005 Lets say for example I want it to permutate 0123456789wtf as many times as possible in a 3 character string without repeating.There are 1320 possible 3-character permutations (draw 3 out of 12). So, you need to find the 220 unique triples and then use my function to permute each of them.CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
anystupidassname Posted August 21, 2005 Author Share Posted August 21, 2005 (edited) There are 1320 possible 3-character permutations (draw 3 out of 12). So, you need to find the 220 unique triples and then use my function to permute each of them.CheersKurt<{POST_SNAPBACK}>@ronsrules: no worries. you've helped no matter what.@/dev/null/: I'm confused. First "0123456789wtf" is 13 characters, not 12.Which would give 1716 and 286.Second, if you "draw 12 out of 3" what happens?I'd like to enter ANY characters to compose the strings with and the string length to output. This could mean "35b6y8w2" output to two character strings or "k2j" output to seven character strings.For the sake of simplicity, I'm holding off on special characters.Am I not understand something or did we have a miscommunication?I appreciate the help! Edited August 21, 2005 by anystupidassname This signature is computer generated, nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#....... Link to comment Share on other sites More sharing options...
/dev/null Posted August 22, 2005 Share Posted August 22, 2005 (edited) @/dev/null/: I'm confused. First "0123456789wtf" is 13 characters, not 12.Which would give 1716 and 286.Ups, sorry I did not count the 0 Second, if you "draw 12 out of 3" what happens?You can't draw 12 auf ot 3, because after 3 items there is nothing left!(without putting items back - which you never mentioned)I'd like to enter ANY characters to compose the strings with and the string length to output. This could mean "35b6y8w2" output to two character strings or "k2j" output to seven character strings.O.K. now I'm confused. I have no idea what you want!CheersKurt Edited August 22, 2005 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
anystupidassname Posted August 22, 2005 Author Share Posted August 22, 2005 O.K. now I'm confused. I have no idea what you want!I will e'splain, no der is too mush, I will sum up...Perhaps I'm using terms improperly... I suppose "permutating items back" as you put it is what I want to do?!? Sorry for being so unclear...Draw 2 out of 4 and you should get 12 right?Then why did I get 16?From "w1t2" output to 2 character string you get:www1wtw21w111t12twt1ttt22w212t22From "w1" output to 3 character string you get:w1wwww1111w111www1w111ww This signature is computer generated, nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#nothing can go wron#....... Link to comment Share on other sites More sharing options...
seandisanti Posted August 22, 2005 Share Posted August 22, 2005 I will e'splain, no der is too mush, I will sum up...Perhaps I'm using terms improperly... I suppose "permutating items back" as you put it is what I want to do?!? Sorry for being so unclear...Draw 2 out of 4 and you should get 12 right?Then why did I get 16?From "w1t2" output to 2 character string you get:www1wtw21w111t12twt1ttt22w212t22From "w1" output to 3 character string you get:w1wwww1111w111www1w111ww<{POST_SNAPBACK}>so you're ok with characters being repeated in output? (2 w's when there was only 1 in the output...) not sure exactly what you're trying to do, but i made a spreadsheet to cheat at wordwhomp on pogo.com a while back that used a similar concept... here is my code on it (vba code, not AutoIT but concepts seem to be the issue not syntax)'******************************************************************************************* 'this is to figure out every possible combination of 1 - 6 without duplicating '*******************************************************************************************' Private Sub getnums() arg = 1 For x = 1 To 666666 'there are 6 characters, for 9 characthers it'd be 999999999 test = CStr(x)'because x is a number have to convert it to a string to check the length If Len(test) > 2 Then donot = False'sets a check condition that if unchanged means the number has no duplicates For y = 1 To Len(test)'checks each digit in the number rest = Right(test, Len(test) - y)'figures out what digits are to the right of the character we want to check achar = Mid(test, y, 1)'decides what char we're looking at If InStr(1, rest, achar) Or Val(achar) > 6 Or Val(achar) = 0 Then donot = True'if our char is at any other position in the string, or if our char is higher than the number of chars (in this case 6) then it would not be a valid combination Next y'next digit If donot = False Then'if the entire number has been checked that no digit occurs more than once and no digit is greater than the number of characters input Range("a" & arg).Formula = test'then the number is added to list of good numbers arg = arg + 1'index is incremented so next good number doesn't overwrite... End If End If Next x End Subok, so that figures out the good numbers to use.in my code i worked with the list of numbers and for each number in the list, i made a string of the characters in the positions...example, if the input string was 'cat' and the number was '321' it would grab 3rd number first, then second then first....'tac'. my code then spell checked it to see if it was a good word and added to a list if it was, but i didn't include that portion as it doesn't really relate. anyway, i hope my code helps somewhat, atleast conceptually... Link to comment Share on other sites More sharing options...
/dev/null Posted August 22, 2005 Share Posted August 22, 2005 (edited) Draw 2 out of 4 and you should get 12 right?Correct. Forumula: m!/(m-n)! ==> 4!/(4-2)! == 12Then why did I get 16?From "w1t2" output to 2 character string you get:wwbecause what you want is not a permutation. See this LINK for an explanation.For your problem use this code:$outputlen = 2 $inputlen = 4 dim $input[$inputlen] = ["w", "1", "t", "2"] dim $index[$outputlen] $nMaxVal = $inputlen ^ $outputlen $msg = "" for $nCounter = 1 to $nMaxVal $output = "" for $i = 0 to $outputlen-1 $output &= $input[$index[$i]] next $msg = $msg & $output & @CRLF $val = $nCounter for $n = $outputlen-1 to 0 step -1 $index[$n] = mod($val,$inputlen) $val = int($val / $inputlen) next next ClipPut($msg)CheersKurt Edited August 22, 2005 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Goutetsu Posted August 22, 2005 Share Posted August 22, 2005 I think a better way of saying what the original poster wants is all possible words of length n given a specific set or alphabet. In that case, lets use your example of "w1t2" and two letter words. x = length of alphabet n = word length So for a word length of 2 you have n^x = 2^4 = 16 possibilities. Which is the number you got. Now could do something like this (pseudocode) : func getwords(alphabet, word length) depth = 1 currword = "" recurseFunc(alphabet, word length, depth, currword) endfunc func recurseFunc(alphabet, word length, depth, currword) char = first char from alphabet while not end of alphabet currword = currword & char if depth == wordlength do_stuff(currword) return else recurseFunc(alphabet, word length, depth, currword) end if wend endfunc Not the greatest, but it is the best I could do off the top of my head. Some of the vars could be global or static (if you can do that with autoit ;-) Link to comment Share on other sites More sharing options...
Gigglestick Posted August 22, 2005 Share Posted August 22, 2005 my code then spell checked it to see if it was a good word and added to a list if it was, but i didn't include that portion as it doesn't really relate. anyway, i hope my code helps somewhat, atleast conceptually...Could you post your code? I'd like to see this in action in Excel. Thanks! My UDFs: ExitCodes Link to comment Share on other sites More sharing options...
/dev/null Posted August 22, 2005 Share Posted August 22, 2005 I think a better way of saying what the original poster wants isall possible words of length n given a specific set or alphabet.That's exactly what my code does.CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
seandisanti Posted August 22, 2005 Share Posted August 22, 2005 Could you post your code? I'd like to see this in action in Excel. Thanks!<{POST_SNAPBACK}>the spreadsheet is on my website (no actual site there, i just use it for web storage) word whomp thingall you have to do is type 6 letters in A1 then click 'cheat' button....i think... heh it's been a while since i made that 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