# Algorithm Needed

I would like to know the shortest fastest algorithm to increment letters of the alphabet. It should start at "a" (ASCII character 97) and increment by one character indefinitely (or at least 50 characters in length) I have provided an example of the output below. SPEED is very important.

a
b
…. (repeat pattern above)

aa
ab
ac
…. (repeat pattern above)

ca
cb
cd
ce

…. (repeat pattern above)

eab
eac
eaf

if you need any clarification please comment.
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Author Commented:
It is possible to do this with nested loops but that is not i what it want because then the length is not variable it is fixed. i want a non-explicityly nested loop solution.

--Jaysor
0
Commented:
here's pseudocode, you can translate it easily into vb I'm sure.
I have every confidence in you ;)

i = 0
loop
{
str = ""
j = i;
while ( j >= 25 )
{
str = ascii(97 + j mod 26 ) + str
j = j / 26
}
output str
i = i + 1
}
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
mjswart,

I think you are on the right track but it seems to not quite output correctly to clarify the out put should start at
"a", "b", "c", "d" until "z" then start again at "aa", "ab", "ac" untill "az" where it will start at "ba", "bb", "bc".
continueing this pattern.. what you did give me does incrament but not in this fashion... I have posted your translated code to see ifyou notice anything wrong with my translation.. please bear witht he poor "formatting"

i = 0

Do

foo = ""
j = i

Do While j >= 25

foo = Chr(97 + j Mod 26) + foo
j = j / 26
Loop

lbl_Display.Caption = foo
lbl_Display.Refresh
i = i + 1

Loop
0
Commented:
I forgot one more line
foo = Chr(97 + j Mod 26) + foo
should be added after the while loop

does this work?
0
Author Commented:
you have that line already there inside the while loop? should it be moved?
0
Author Commented:
and for your trouble imm increasing the points to 150,, its all i got.. sorry but i thank you for helping
0
Commented:
nope there should be two lines
one in the loop
and one just after
0
Author Commented:
getting closer, but it does do all possiblities but it does not do them sequentally..
0
Commented:
I got it!
change Do While j >= 25
to Do While j > 25

also use j = j\26,
this gives j an integer result rather than floating,
tell me if this works
0
Commented:
This should do it (tested by me finally)

i = 0
Do
foo = ""
j = i
Do While j > 25
foo = Chr(97 + j Mod 26) + foo
j = (j \ 26) -1
Loop
foo = Chr(97 + j Mod 26) + foo
output
i = i + 1
Loop
0
Author Commented:
btw thank you.
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.