Jump to content

Making A Script To Write All Possible Combinations...


sherkas
 Share

Recommended Posts

Im trying to get logic down and code this.

I want a program to generate all possible combinations of letters and numbers for X digits.

I cant think of how to start the loops.

I was thinking, for all digits, do a loop for all possible letters/numbers

but the problem is this.

I want say for 10 digits to generate the combinations:

a

aa

aaa

aaaa

b

bbb

c

ccc

abcd

abc

abcde

etc...

all combinations even 1 digits. So for UP TO X digits i should say.

Can someone help me with some logic on how to start this?

Link to comment
Share on other sites

this is one way...

#include <Array.au3>

Dim $R[6]

Randomize()

_ArrayDisplay( $R, " Array")

Func Randomize()
$R[1] = Random(1, 47, 1)
$R[2] = Random(1, 47, 1)
$R[3] = Random(1, 47, 1)
$R[4] = Random(1, 47, 1)
$R[5] = Random(1, 47, 1)
If $R[1] = $R[2] Or $R[1] = $R[3] Or $R[1] = $R[4] Or $R[1] = $R[5] Then Randomize ()
If $R[2] = $R[3] Or $R[2] = $R[4] Or $R[2] = $R[5] Then Randomize ()
If $R[3] = $R[4] Or $R[3] = $R[5] Then Randomize ()
If $R[4] = $R[5] Then Randomize ()
_ArraySort($R, 0, 1)
EndFunc

8)

NEWHeader1.png

Link to comment
Share on other sites

That is a random way...

but i dont think its quite what im looking for

yea well this is random also... but it does what you wanted... and couldn't get your "head around"

this does 10 digit combinations... none are the same, you can change it to start with 1, then 2 then 3... etc if you want

Dim $combo[1000], $t, $combo_test, $N, $L, $j

Run("notepad.exe")
WinWaitActive("")
Sleep(500)

$Letter = StringSplit("A,B,C,D,E,F,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z", ",")
$Number = StringSplit("0,1,2,3,4,5,6,7,8,9", ",")

While $j < UBound($combo) - 1
    Get_combo()
    For $t = 1 To UBound($combo) - 1
        If $combo[$t] = $combo_test Then ExitLoop
        If $combo[$t] = "" Then
            $combo[$t] = $combo_test
            $j = $j + 1
    ;MsgBox(64, "Combonation " & $t, $combo[$t] & '   ', 1)
            Send("Combonation " & $t & " = " & $combo[$t] & @CRLF)
            Sleep(300)
            ExitLoop
        EndIf
    Next
WEnd

Func Get_combo()
    $combo_test = ""
    While StringLen($combo_test) < 10
        $L = $Letter[ (Random(1, $Letter[0], 1)) ]
        $N = $Number[ (Random(1, $Number[0], 1)) ]
        $test = Random(1, 2, 1)
        If $test = 1 Then
            $combo_test = $combo_test & $L
        Else
            $combo_test = $combo_test & $N
        EndIf
    WEnd
EndFunc ;==>Get_combo

tested to over 500.. then i exited................. Thanks Valuater

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

hmm I guess i need to really read it and understand it, because i tested it and saw that it worked, but.... i didn't see how it being random would do it.

than ks, will read this and try tounderstand it.

Link to comment
Share on other sites

Try this

Run("notepad.exe")
WinWaitActive("")
Sleep(500)
$Letter = StringSplit("A,B,C,D,E,F,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,0,1,2,3,4,5,6,7,8,9", ",")
Combi("", 5)
Func Combi($Str, $MaxLen)
Dim $i
    if StringLen($Str) = $MaxLen Then
        Send("Combination = " & $Str & @CRLF)
;       Sleep(50)
        Return
    EndIf
    For $i = 1 to $Letter[0]
        Combi($Str & $Letter[$i], $MaxLen)
    Next
EndFunc

Pure recursion

Link to comment
Share on other sites

  • 10 years later...
  • Moderators

@chacoya121 did you happen to notice this thread is over 11 years old? Please don't resurrect old threads. If you have a question, create a new thread (in the correct section such as General Help and Support not the Examples forum), and explain what you're trying to accomplish.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

@chacoya121 With your new topic in General Help & Support, you could also include a link back to this topic, which might also make it clearer for those trying to help you. :)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...