Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 546773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:54:09+00:00 2026-05-13T10:54:09+00:00

I need a counter algortihm which use arbitrary given digits for counting purpose. My

  • 0

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 */
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:54:09+00:00Added an answer on May 13, 2026 at 10:54 am

    It’s quite simple. You want to convert into base digit_count and then instead of converting the digits to numbers, you index into your array.

    To convert to an arbitrary base, you need division and remainder.

    Here’s a better version than what I used before because it actually creates a buffer (rather than prints it out), drops recursion for iteration and is in C instead of my previous C/Python hodgepodge.

    Because it uses a static buffer, the code is not thread safe. Also note that there is no error checking that the code doesn’t underflow the buffer if the number is too large. Finally, it uses a trick of building the string from the end to the front and returning a pointer to the middle of the buffer so it doesn’t have to reverse the digits at the end.

    char *getnum(int x)
    {
        static char buffer[1024];
        int idx = 1024;
    
        buffer[--idx] = '\0';
    
        if (x == 0)
            buffer[--idx] = digits[0];
        else
        {
            while (x != 0)
            {
                buffer[--idx] = digits[x % digit_count];
                x /= digit_count;
            }
        }    
    
        return buffer + idx;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 387k
  • Answers 388k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use NUnit: http://www.nunit.org/ May 15, 2026 at 12:16 am
  • Editorial Team
    Editorial Team added an answer Java SE = Standard Edition. This is the core Java… May 15, 2026 at 12:16 am
  • Editorial Team
    Editorial Team added an answer Insert the (?s) modifier in the regex. That's equivalent to… May 15, 2026 at 12:16 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.