Jump to content

need help generating a list


Sarc
 Share

Recommended Posts

hello

i need advice on a script that will create an incrementing list with the following letters, as follows

the letters to be used are:

b g h i j k l m n o p u t

and i need them to be generated as a list, all combinations possible with a maximum of 3 letters:

b, g, h, i, j, k, l, m, n, o, p, u, t,

bb bg bh bi bj bk bl bm bn bo bp bu bt

gb gg... etc

then bbb bbg... bgb...

i need it do do this upto:

ttp ttu ttt

these then have to be put into a variablo $var or whater its gona b called

can any1 help?

Thanx

Edited by Sarc
Link to comment
Share on other sites

Okay -- this is a matter of array looping I would think...

Dim $letters = StringSplit("b,g,h,i,j,k,l,m,n,o,p,u,t", ",")
Dim $var
; For the 2 letter combos
For $i = 1 To $letters[0]
   For $j = 1 To $letters[0]
     $var = $var + letters[$i] + letters[$j] + " "
   Next 
Next 
; For 3 letters
For $i = 1 To $letters[0]
   For $j = 1 To $letters[0]
      For $k = 1 To $letters[0]
         $var = $var + letters[$i] + letters[$j] + letters[$k] + " "
      Next  
   Next 
Next

I didn't test this, but it should be right.

Andrew

Link to comment
Share on other sites

  • Developers

here is a generator i wrote a while ago...

Just enter your characters in the first line and it will generate a file for all possibilitie...

$STR="A,B,C,D,E,F,G"
$CHARS=StringSplit($STR,",")
$FILE = FileOpen("test.txt", 2)
$MLEN = 4; max length of the output
$TOUT=""
Dim $NTOUT[$MLEN+1] 
For $X = 1 To $MLEN
   $NTOUT[$X] = Chr(0)
Next
$NTOUT[1] = Chr(0)
; endless loop
While 1=1
   For $X = 1 To $CHARS[0]
      FileWriteLine($FILE, $TOUT & $CHARS[$X] & @LF) 
   Next
   $TOUT=""
   $N2 = 0
   For $X = 1 To $MLEN
      If $X = 1 Then
         $N = Asc($NTOUT[$X]) + 1
      Else
         $N = Asc($NTOUT[$X]) + $N2
      EndIf
      $N2 = 0
      If $N > $CHARS[0] Then
         $N = 1
         $N2 = 1
      EndIf
      $NTOUT[$X]=Chr($N)
      If $N > 0 Then
         $TOUT=$CHARS[$N] & $TOUT
      EndIf
   Next
   If StringLen($TOUT) = $MLEN Then
      ExitLoop
   EndIf
Wend
FileClose($FILE)
Exit
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

nice guys thanx

i'm at school at the mo but i'll try both of them tonight

@both:

where is the list generated... like is it output to a txt file (cudnt c that) or is it just stored into a variable

real purpose for this is i've lost the password to an account on a game, and i know the letters that i used (the ones listed above) therefore i was gona use this as a way to try until i get my password :)

thanx

Link to comment
Share on other sites

i tested yours andrew and there seems to be some errors when compiling ir which i didnt know how to correct

i tested yours JdeB and sure enough, it wrote to a text file "test.txt" however it was all in blocks... ie i cudnt see any characters but it certainly generated a list of something

if either of you could tell me how to correct or whatever then that'd be awesome

Thanx

Link to comment
Share on other sites

  • Developers

i tested yours JdeB and sure enough, it wrote to a text file "test.txt" however it was all in blocks... ie i cudnt see any characters but it certainly generated a list of something

<{POST_SNAPBACK}>

Dunno what you mean..... it creates all possible combinations of the characters specified in the $str... and yes it writes it to a file in the example posted...

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

it writes to the file yes, but instead of A B C.. etc, all of the characters are replaced with Squares, as if there is no character to display (i think) so i cant actually see the combinations

EDIT: i changted the size from 4 to 3 and it works now, so thx :)

is there any way (if it hasnt been done already - i cant tell as im a novice proigrammer) that all of these outcomes could be stored in an array, so i can call array[0] to give me A, array[1] to give B... etc?

Edited by Sarc
Link to comment
Share on other sites

  • Developers

it writes to the file yes, but instead of A B C.. etc, all of the characters are replaced with Squares, as if there is no character to display (i think) so i cant actually see the combinations

EDIT: i changted the size from 4 to 3 and it works now, so thx :)

is there any way (if it hasnt been done already - i cant tell as im a novice proigrammer) that all of these outcomes could be stored in an array,  so i can call array[0] to give me A, array[1] to give B... etc?

<{POST_SNAPBACK}>

Just give it a try .... its not that difficult .... :D

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

ok well lets say i make a variable $now to count the number of words produced, then i think i'd do the following... pls correct if im terribly wrong.. i prolly will be :D

i dont understand which the current word variable is so i'll use $wordvar as that

dim $array(1 to $now)

for $c = 1 to $now
          $array($c) = $array($c) + asc($wordvar)
next

.. i tried? :)

Link to comment
Share on other sites

  • Developers

ok well lets say i make a variable $now to count the number of words produced, then i think i'd do the following... pls correct if im terribly wrong.. i prolly will be  :D

i dont understand which the current word variable is so i'll use $wordvar as that

dim $array(1 to $now)

for $c = 1 to $now
          $array($c) = $array($c) + asc($wordvar)
next

.. i tried?  :)

<{POST_SNAPBACK}>

You are getting closer but need to study the helpfile a bit more for Array info....

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

any 1??

<{POST_SNAPBACK}>

This example will create an Array $Output that contains all entries when the script is done... (the rest is yours to figure out... :) )

#include <array.au3>
$STR = "A,B,C,D,E,F,G"
$CHARS = StringSplit($STR, ",")
$MLEN = 3; max length of the output
$TOUT = ""
Dim $OCount = 0
Dim $NTOUT[$MLEN + 1]
For $X = 1 To $MLEN
    $NTOUT[$X] = Chr(0)
;calculate the number of possibilities
    $OCount = $OCount + $CHARS[0] ^ $X  
Next
$NTOUT[1] = Chr(0)
Dim $output[$OCount + 1]
$OCount= 0
; endless loop
Do
    For $X = 1 To $CHARS[0]
        $OCount = $OCount + 1
        $output[$OCount] = $TOUT & $CHARS[$X]
    Next
    $TOUT = ""
    $N2 = 0
    For $X = 1 To $MLEN
        If $X = 1 Then
            $N = Asc($NTOUT[$X]) + 1
        Else
            $N = Asc($NTOUT[$X]) + $N2
        EndIf
        $N2 = 0
        If $N > $CHARS[0] Then
            $N = 1
            $N2 = 1
        EndIf
        $NTOUT[$X] = Chr($N)
        If $N > 0 Then
            $TOUT = $CHARS[$N] & $TOUT
        EndIf
    Next
Until StringLen($TOUT) = $MLEN

; put here your code to read the array....

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

This example will create an Array $Output that contains all entries when the script is done...  (the rest is yours to figure out...  :)  )

#include <array.au3>
$STR = "A,B,C,D,E,F,G"
$CHARS = StringSplit($STR, ",")
$MLEN = 3; max length of the output
$TOUT = ""
Dim $OCount = 0
Dim $NTOUT[$MLEN + 1]
For $X = 1 To $MLEN
    $NTOUT[$X] = Chr(0)
;calculate the number of possibilities
    $OCount = $OCount + $CHARS[0] ^ $X  
Next
$NTOUT[1] = Chr(0)
Dim $output[$OCount + 1]
$OCount= 0
; endless loop
Do
    For $X = 1 To $CHARS[0]
        $OCount = $OCount + 1
        $output[$OCount] = $TOUT & $CHARS[$X]
    Next
    $TOUT = ""
    $N2 = 0
    For $X = 1 To $MLEN
        If $X = 1 Then
            $N = Asc($NTOUT[$X]) + 1
        Else
            $N = Asc($NTOUT[$X]) + $N2
        EndIf
        $N2 = 0
        If $N > $CHARS[0] Then
            $N = 1
            $N2 = 1
        EndIf
        $NTOUT[$X] = Chr($N)
        If $N > 0 Then
            $TOUT = $CHARS[$N] & $TOUT
        EndIf
    Next
Until StringLen($TOUT) = $MLEN

; put here your code to read the array....

<{POST_SNAPBACK}>

.. i dont get it..... read the array... u mean like from here i can use the array as i want to?

for $a = 1 to $oCount
msgbox(1,"Array",$output[$a])
$a = $a+1
Next

this wud loop message boxes giving all of the array values stored..? or do i still need to do more to the script u posted to have it work..?.. like im not understanding if u mean the list will be generated into that array or if i still have to do more....

Link to comment
Share on other sites

  • Developers

.. i dont get it.....      read the array... u mean like from here i can use the array as i want to?

for $a = 1 to $oCount
msgbox(1,"Array",$output[$a])
$a = $a+1
Next

this wud loop message boxes giving all of the array values stored..? or do i still need to do more to the script u posted to have it work..?.. like im not understanding if u mean the list will be generated into that array or if i still have to do more....

<{POST_SNAPBACK}>

Try to understand the language first... one step at a time...... read about For...Next loops first... understand what it does.... then read your own code again and see if it still makes sence.

happy reading.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

if u mean the code that i wrote looping the array mesages then i dont see anything wrong...?

sure, i havent used this "complex" a level of autoit before but the experience i've had from vb and some C/C++ it looks fine so im confused as to what you mean

EDIT:

have now annotated the code

for $a = 1 to $oCount;says that it will loop from 1 to $OCount and $OCount has been the maximum number from the combo's generated
msgbox(1,"Array",$output[$a]);sends a msgbox for the current loop's array
$a = $a+1;increments the value of a$ as to make it closer towards $OCount
Next; goes back to the start of the for loop to do it again

hmm..?

Edited by Sarc
Link to comment
Share on other sites

ah

thats prolly why i was confused

lets c then

Edit: have annoteted code

#include <array.au3>;includes the library that sez about arrays etc...
$STR = "A,B,C,D,E,F,G";sets what chars are to be used
$CHARS = StringSplit($STR, ",");********************************
$MLEN = 3; max length of the output  -----> no need to annotate here..
$TOUT = ""
Dim $OCount = 0;declares that $OCount = 0
Dim $NTOUT[$MLEN + 1];declares that $NTOUT = $MLEN(3) + 1 = 4


;section explained underneath
For $X = 1 To $MLEN;uses a for loop from 1 to 3
    $NTOUT[$X] = Chr(0)
;calculate the number of possibilities
    $OCount = $OCount + $CHARS[0] ^ $X  
Next
;calculates how many values ther's gona be... if $x = 1, 2, 3 there will be ...... calculated things


$NTOUT[1] = Chr(0);******************
Dim $output[$OCount + 1];increments the $OCount location inside the array to select the next free one for writing
$OCount= 0
; endless loop
Do
    For $X = 1 To $CHARS[0];sets up a for loop
        $OCount = $OCount + 1;increments $OCount
        $output[$OCount] = $TOUT & $CHARS[$X];sets the $output value (stored in location $OCount) as the generated letters
    Next;sends it back to loop

;from here i'm not 100% sure but im guessing its checking something
    $TOUT = ""
    $N2 = 0
    For $X = 1 To $MLEN
        If $X = 1 Then
            $N = Asc($NTOUT[$X]) + 1
        Else
            $N = Asc($NTOUT[$X]) + $N2
        EndIf
        $N2 = 0
        If $N > $CHARS[0] Then
            $N = 1
            $N2 = 1
        EndIf
        $NTOUT[$X] = Chr($N)
        If $N > 0 Then
            $TOUT = $CHARS[$N] & $TOUT
        EndIf
    Next
Until StringLen($TOUT) = $MLEN;until the generated string reached its maximum (=3)

the bits labelled ;********************** i'm not sure on

care to explain pls?

Edited by Sarc
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...