Jump to content

create all possible words from string


Recommended Posts

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.

Link to post
Share on other sites
  • Developers

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

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 post
Share on other sites
  • Developers

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

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 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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...