I need a counter algortihm which use arbitrary given digits for counting purpose.
My code is similar to this:
static char digits[] = {'x','y','z'}; /* Arbitrary number of arbitrary digits. */
int i;
for(i=0; i<100; i++) {
printf("%s\n", get_next());
}
My expected output:
x
y
z
yx
yy
yz
zx
zy
zz
yxx
yxy
yxz
yyx
yyy
yyz
yzx
yzy
yzz
zxx
... and so on
As you see, I need algorithm for implementing get_next()
function, so using C language is not the point.
Edit I for clarification purpose:
My get_next() function may similar to this:
char get_next() {
static previous = digits[0];
char *next_number;
/* do something here using previous and digits[] */
return next_number;
}
Note that using get_next(void)
or next(previous_number)
or next(digits, previous_number)
prototype for your function which generates next number is not important for me.
Edit II for clarification purpose:
My real scenario is more complex from the simple example above, I need a generic solution that works with arbitrary number of arbitrary digits.
Example digit inputs:
static char digits[] = {'a', 'b', 'c', ... 'z', '0', '1', ...}; /* Lots of digits */
static char digits[] = {'s','t','a','c','k','o','v','e','r'}; /* Arbitrary sequence */