1. ## character combinations

Hello all.
I need a function that produces this strings
a , b, aa ,ab, ba ,bb ,aaa,aab, aba ,abb baa ,bab ,bba , bbb ,aaaa...
It 's NOT exactly like binary counting (in binary after bbb (111) is aaaa (1000))

char* GetNextString(char* previous)

i.e . GetNextString("bba")="bbb" , GetNextString("bbb")="aaaa"
I hope you understand what i need
Thank you !

2. I need a death ray. I need it to be able to wipe out entire armies and lots of buildings.

How about you give me the death ray and I give you your GetNextString() function?

3. > It 's NOT exactly like binary counting
Close enough though.
Once you understand base 2 counting, plus I take it you already understand base 10 counting, then figuring out base 26 counting should be easy.

4. Originally Posted by Salem
> It 's NOT exactly like binary counting
Close enough though.
Once you understand base 2 counting, plus I take it you already understand base 10 counting, then figuring out base 26 counting should be easy.
This isn't base 26, he's using only a's and b's. And like he said, it's not the same as counting, since if we just say a is 0 and b is 1, then the increasing series would be:

a, b, ba, bb, baa, bab, bba, bbb...

That's not the series he wants.

5. External loop is on string length
Internal - is just a binary counter from 0 to 2^k-1
for example for k = 3
0 - 000 - aaa
1 - 001 - aab
2 - 010 - aba
etc

6. Originally Posted by vart
External loop is on string length
Internal - is just a binary counter from 0 to 2^k-1
for example for k = 3
0 - 000 - aaa
1 - 001 - aab
2 - 010 - aba
etc
But again, that's not the sequence he wants. What he wants is a lexicographic ordering of all strings of a's and b's. That is NOT the same as simple digital counting.

EDIT: I'm stupid. Didn't fully comprehend what you wrote. Your method is right

7. Wow MacGyver you must really want a death ray :|

8. Originally Posted by Salem
> It 's NOT exactly like binary counting
Close enough though.
Once you understand base 2 counting, plus I take it you already understand base 10 counting, then figuring out base 26 counting should be easy.
Binary counting is not enaugh becauce has a 2^k limit (k=32 or 64) .I need combinations up to 1000 caracters(2^1000!!!).
If this is easier i want this order 1-digit , 2-digit ..... n-digit (combinations )
No problem if "bb" is before "ab" but a 5-digit combination cant be after a 6-digit combination.

9. I need combinations up to 1000 caracters
So? What is the problem?

10. Originally Posted by vart
So? What is the problem?
I cant write : for(int i=0; i<2^500;i++)
I think is better working with strings.

11. Code:
```char* incrementString(char* str)
{
size_t len = strlen(str);
size_t index;
for(index = len; index > 0; index--)
{
if(str[index-1] == 'a')
{
str[index-1] = 'b'; /* and exit */
return str;
}
/* we have 'b' - increment it and go to the next char */
str[index-1] = 'a';
}
/* all chars were 'b' - now they all are reset to 'a'
* return NULL pointer to indicate the end of iterations
* calling function should append 'a' to the string and run the loop again
* if the desired string length  is not achieved
*/
return NULL;
}```
Have not compiled or tested the code - but hope it shows the idea of incrementing arbitrary length string