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 7741593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:04:00+00:00 2026-06-01T09:04:00+00:00

I have 20 different variable-length arrays, each holding a unique value, and I need

  • 0

I have 20 different variable-length arrays, each holding a unique value, and I need to calculate every possible combination of these:

#define LENGTH_COUNT 6
#define WIDTH_COUNT 4
etc, for all 20 arrays:

int length[LENGTH_COUNT];
int width[WIDTH_COUNT];
int height[HEIGHT_COUNT];
int weight[WEIGHT_COUNT];
int growth[GROWTH_COUNT];
int decay[DECAY_COUNT];
int sound[SOUND_COUNT];
int texture[TEXTURE_COUNT];
int moisture[MOISTURE_COUNT];
int volume[VOLUME_COUNT];
int speed[SPEED_COUNT];
int color[COLOR_COUNT];
int purpose[PURPOSE_COUNT];
int delay[DELAY_COUNT];
int vibrancy[VIBRANCY_COUNT];
int brix[BRIX_COUNT];
int ripeness[RIPENESS_COUNT];
int mold[MOLD_COUNT];
int temp[TEMP_COUNT];
int language[LANGUAGE_COUNT];


void iterate(void)
{
    for (int i = 0; i < LENGTH_COUNT; ++i)
          for (int j = 0; j < WIDTH_COUNT; ++j)
                for (int k = 0; k < HEIGHT_COUNT; ++k)
                // etc for all 20 arrays
                    int value = doSomething(length[i], width[j], height[k].....);
}

There must be a less brain-dead way to do this. One idea I had is:

#define ARRAY_COUNT  20
#define MAX_LENGTH 12   // the longest array length is 12
int arrays[ARRAY_COUNT][MAX_LENGTH];

But if I were to do this, I don’t know how to do the equivalent to what
I am doing in the iterate function.
Any ideas?

  • 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-06-01T09:04:01+00:00Added an answer on June 1, 2026 at 9:04 am

    You could create (untested/uncompiled):

    int *arrays[] = { first_arr, second_arr, ... }; // array of arrays
    int maxes[] = { FIRST_ARR_MAX, SECOND_ARR_MAX, ... }; // array of array lengths
    int counter[NUM_ARRAYS] = {0}; // initialize a counter to 0 for each of the arrays.
    
    int state = 0;
    
    while (true) {
        doSomething(first_arr[counter[0]], second_arr[counter[1]], ... );
    
        // Update the counter.
        int i;
        for (i = NUM_ARRAYS - 1; i >= 0; i--) {
            counter[i]++;
            // If incrementing the current counter didn't overflow, we're good, so we break.
            if (counter[i] < maxes[i]) {
                break;
            } else {
                // Overflow by setting the counter to 0.
                counter[i] = 0;
                // Now we will fall through and move to the next counter.
            }
        }
        // Check for all 0's intelligently.  State == 0 means counter[0] is 0.
        // If it's no longer 0, move to state 1.
        if (state == 0 && counter[0] > 0) {
            state = 1;
        } else (state == 1 && counter[0] == 0) {
            break;
        }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to initialize a script variable in a for loop with different values
I have different urls that points to the same code www.url1.com www.url2.com I need
I have a DataGrid whose dataProvider is an Array of int Arrays (each with
I have a child process which generates some output of variable length and then
I want to plot several curves, each having a different length. So, I've placed
I have the same block of code repeated with two different variables. This block
I have some user-submitted variables that I want to display in a different part
I didn't have a understanding on difference between intializing a variable with {} and
I have different php output in jQuery-based tabs. This output is formed from database
I have different projects written in .NET 3.5 and some unit test projects to

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.