Autohotkey - Bicycle Letter

I am a math student and I know modular arithmetic that will most likely help.

I want code in Autohotkey or autoit, on key press I want to run a sequence of input commands, like:

A A A A A A A A Enter

A A A A A A A B Enter

...

A A A A A A B A Enter

and etc.

I want to cycle through letters up to

Z Z Z Z Z Z Z Z Enter

I want to generate all 12 permutations of letter length a-z

separated byEnter

I will try to work as I do, any advice is appreciated.

+3


source to share


1 answer


Almost the same question was asked 2 weeks ago: Counting with AHK, Emails But I'll happily answer that again:
(click the link above for an example with no comments, it's pretty messy here)

BruteForce(Chars, Min, Max, Prefix:="", Stage:=0) { ;function header
   Loop, Parse, Chars ;We loop through the character string that we are gonna pass to this function
   {
      If (Stage >= Min-1) { ;explained in the second if block
           ;Prefix: our last generated string (at the first iteration AAAAAAAAAAA (11 As))
           ;A_LoopField: contains current character of the "Chars" string that we are looping through
           ;"{Enter}": to tell SendInput to send an Enter after the Prefix and the current char
         SendInput % Prefix A_loopField "{Enter}" ;AAAAAAAAAAA A {Enter}
      }
      If (Stage < Max-1) { 
           ;at this point it get really tricky
           ;it kinda hard to explain what exactly happens here
           ;and at the same time pretty selfexplainatory if you simply know the used AHK commands/keywords

           ;Basically what happens here is, the function is going to call itself again without leaving the loop
           ;increasing the state step by step (everytime we get here) until we reach (in this case) 12-1 so 11
           ;during the first "iteration" (in this case) we will be adding an A to the prefix parameter everytime the function re-calls itself
           ;when it reached 11, then it generated the string AAAAAAAAAAA (11 As)
           ;since the is at this point the expression state >= Min-1 (we passed a 12 for Min) is true
           ;we will output the the string + the current char (A) in the if block above
           ;then the second if statement will fail 
           ;and the loop of the current function call will go into it second iteration
           ;and output again 11 As and our second character (B)
           ;etc etc until the loop is over, then the last function call is over and it will go to the one from before... 
           ;as I said... really hard to explain. to understnad it you are best of with simply going through the code like it would be executed and maybe take some notes of what has happened in each iteration
         BruteForce(Chars, Min, Max, Prefix A_LoopField, Stage + 1)
      }
   }
}

F1:: ;hotkey is F1
    BruteForce("ABCDEFGHIJKLMNOPQRSTUVWXYZ", 12, 12) ;this would send possible combination of capital letters (min length 12, max length 12)
    ;you can change the min length and max length, as well as the character string however you want
Return

      

And here's another approach that will give more sorted output if min and max lengths are not the same:



Generate(prefix, len, chars) {
    If (StrLen(prefix) = len)
        SendInput % prefix " "
    If (StrLen(prefix) < len)
        Loop, Parse, chars
            Generate(prefix A_LoopField, len, chars) 
}

BruteForce(chars, minLen, maxLen) {
    curLen := minLen
    Loop % maxLen-minLen+1 {
        Generate("", curLen, chars)
        curLen++
    }
}

F1::
   BruteForce("abc", 2, 3)
Return

      

The output would be: aa ab ac ba bb bc ca cb cc aaa aab aac aba abb abc aca acb acc baa bab bac bba bbb bbc bca bcb bcc caa cab cac cba cbb cbc cca ccb ccc

+3


source







All Articles