# Algorithmic question

## Recommended Posts

Ok..I've been meaning to write something like this in a "classical" programming language for some time now..but I could never get around it..I've heard I need to use backtracking, but I'm not exactly good at algorithms, and I would like to take advantage of whatever functions AutoIt has and NOT make a messy implementation of my "algorithm"..Ok..Enough ranting..here's the thing..

Suppose I have an array of characters..(a string would be better in this case)..

\$charlist="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" and so on

now..

Supposing I need a string of a certain length that would be the logical continuation of another..

Supposing I'm using the \$charlist above and a 4 char-string..

s="ttyz"..the next string would be s="ttyA" and then the next would s="ttyB" aso until s="tty0", then the string should become "ttza"..

Are you feeling me?And so on until "tt00", then it should be "tuaa" aso aso aso..

I'm not great at implementing algs..

So I would need a function say..NextString(\$s,\$charlist) that would give me the string next from \$s..I just need the basic thing..anything like error-checking should be easy enough..like if any char in \$s is not in \$charlist, it would set @error to 1 and bail out..

Thank you in advance..an example would be great..

[quote]Together we might liveDivided we must fall[/quote]

##### Share on other sites

Think of it sort of like a car odometre. The 2nd digit can only move until the first digit turns zero. So I'm thinking using StringSplit for the characters, and use If statements for the characters, and have the whole thing in a For...Next/While...Wend. And each time one of the characters does a revolution it add's 1, hence like an odometre. It depends on the requirements but... such as,

• The starting letter(s)
• The length of the string
Edited by Burrup

qq

##### Share on other sites

K..I feel you..Can you give me an example for the function?(One that works)..I had a VERY messy method and it depended on string length, and if I really wanted to do something REALLY messy, I would say

if \$slength=1 then next1(\$s)

if \$slength=2 then next2(\$s)

...

But I'm sure there's a better way..

[quote]Together we might liveDivided we must fall[/quote]

##### Share on other sites

Ok, I'll try make an example. Just tell me the string length, the starting letters and the ending letters. Theres a post floating around somewhere about how to generate all the possibilites for a certain amount of letters. Eg. If the input was "ab" it would generate.

aa, ab, bb, ba.

Edited by Burrup

qq

##### Share on other sites

That doesn't really help out..Those are called Permutations(if I can do ad-litteram translations of romanian terms)Um..well..the stringlength is N and the starting and ending letters are in a string called \$charset..

\$charset="WHATEVER"

\$stringlength=5

Or anything..It should work for random values..I'm gonna try and see if I can cook up something..This AutoIt Enviroment beats the shit outta Borland Pascal 7.1..so I should be getting many more ideas

Cheers..thanks for caring..

[quote]Together we might liveDivided we must fall[/quote]

##### Share on other sites

Is this what you are looking for?

```;==============
; Example
;==============
AutoItSetOption("MustDeclareVars", 1)
Const \$ForReading = 0, \$ForAppending = 1, \$ForWriting = 2
Dim \$SampleChars, \$CurrString, \$f
\$SampleChars = "abcdABCD123"
\$CurrString = "B1D"
\$f = FileOpen("c:\temp\test.txt", \$ForWriting)
for \$j = 1 To 1000
\$CurrString = NextString( \$CurrString, \$SampleChars)
If @error < 1 Then
FileWriteLine(\$f, \$CurrString)
Else
FileWriteLine(\$f, "Out of range")
ExitLoop
EndIf
Next
FileClose(\$f)
;==============
; End Example
;==============

Func NextString(\$s,\$charlist)
; Return the next string in the sequence
Dim \$sA, \$i, \$charListLen, \$next, \$addOne
\$charListLen = StringLen(\$charlist)
If StringLen(\$s) = 0 Then SetError(1)
If StringLen(\$charlist) = 0 Then SetError(1)
\$sA = StringSplit(\$s, "")
for \$i = \$sA[0] to 1 Step -1
If \$sA[\$i] == StringRight(\$charlist, 1) Then
If \$i = 1 Then
SetError(2)   ; Exceeded end of sequence
Else
\$sA[\$i] = StringLeft(\$charlist, 1)
EndIf
Else
\$sA[\$i] = StringMid(\$charlist, StringInStr(\$charlist, \$sA[\$i], 1) + 1, 1)
EndIf
EndIf
Next
For \$i = 1 To \$sA[0]
\$next = \$next & \$sA[\$i]
Next
Return \$next
EndFunc```

It was fun!

BlueBearr

BlueBearrOddly enough, this is what I do for fun.
##### Share on other sites

Lol..Ok..I gotta admit..that's kewel..Didn't quite begin studying it yet..I slept a bit on it and made a version in PASCAL using a recursive function..and if I couldn't implement it in AutoIt, I would've ran the exe and fetched the value from a file or something..anyway..GREAT work..And thanks alot!

God..I'm looking at the code right now and realising I have alot to learn STILL about AutoIt..hey...thanks alot, man..You've done me a great service!..

[quote]Together we might liveDivided we must fall[/quote]

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...