Sign in to follow this  
Followers 0
boringduck

create all possible words from string

8 posts in this topic

heeeeelp....

Hello,

Is this possible....

i have a string 'abcdefg'

and i want to make a script to make all possible words from this string....

for example: a, ab, ac,.... agaaaa etc.....

thanks for the help....

:iamstupid:

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

To be honest, that would be an endless loop as the one you described, now if you only allowed all the letters to be used once, or only as many as the total you have it may work without going into an endless loop.

Do you want it to do all possible answers with only the letters used max once?

IE: "abc"

a

b

c

ab

ac

bc

ba

ca

cb

abc

acb

bac

bca

cab

cba

?

Boggle or something? I forgot exactly how this is done, but I would start by putting them all into an array, ex:

dim $c[10]
$x="abc"
$y=$x
$count=0
while StringLen ($y)>0
$c[$count]=StringLeft($y, 1 ) 
$y=StringTrimLeft( $y,1 ) 
$count=$count+1
Wend 
msgbox(1,$x, $c[0]&@lf&$c[1]&@lf&$c[2])

sloppy, but easy to understand I think.

This one changes the array depending on how many entered. I thought a bit about it, but too early in the morning for me yet.

$x=InputBox("Question", "What set of letters?", "", "", -1, -1, 0, 0)
dim $c[StringLen($x)]
;$x="abc"
$y=$x
$count=0
while StringLen ($y)>0
$c[$count]=StringLeft($y, 1 ) 
$y=StringTrimLeft( $y,1 ) 
$count=$count+1
Wend 
$out=""
for $c1= 0 to $count-1
$out=$out & $c[$c1] & @lf
next
msgbox(1,$x, $out)
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Already thanks for the help but It should be possible that for exemple the a is used 2 or more times in the same word....

Share this post


Link to post
Share on other sites

B) Sounds like password hacking to me :whistle:

What max length word should it be or is it unlimited ??


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

the length of the word should be variable... :whistle:

Share this post


Link to post
Share on other sites

this script will generate a file test.txt that contains all possibilities of the characters put in the $STR var. $Mlen sets the lenght limit

Jos

$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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

nice JdeB, :whistle:

I stopped thinking about it when I thought of the uses. Nice way to do it, AutoIt is very versitile.


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I know what it could be used for (I mentioned that in my earlier post...

but just wanted to see if it was possible...

and thought ... 'What the HACK' :whistle:

that shouldn't be my problem....

Jos

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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
Sign in to follow this  
Followers 0