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

  • Home
  • SEARCH
  • 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 8956865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:51:48+00:00 2026-06-15T14:51:48+00:00

The idea is, given an n number of spaces, empty fields, or what have

  • 0

The idea is, given an n number of spaces, empty fields, or what have you, I can place in either a number from 0 to m. So if I have two spaces and just 01 , the outcome would be:
(0 1)
(1 0)
(0 0)
(1 1)

if i had two spaces and three numbers (0 1 2) the outcome would be

(0 1)
(1 1)
(0 2)
(2 0)
(2 2)
(2 1)

and so on until I got all 9 (3^2) possible outcomes.

So i’m trying to write a program that will give me all possible outcomes if I have n spaces and can place in any number from 0 to m in any one of those spaces.

Originally I thought to use for loops but that was quickly shotdown when I realzed I’d have to make one for every number up through n, and that it wouldn’t work for cases where n is bigger.

I had the idea to use a random number generator and generate a number from 0 to m but that won’t guarantee I’ll actually get all the possible outcomes.

I am stuck 🙁

Ideas?

Any help is much appreciated 🙂

  • 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-15T14:51:48+00:00Added an answer on June 15, 2026 at 2:51 pm

    Basically what you will need is a starting point, ending point, and a way to convert from each state to the next state. For example, a recursive function that is able to add one number to the smallest pace value that you need, and when it is larger than the maximum, to increment the next larger number and set the current one back to zero.

    Take this for example:

    #include <iostream>
    #include <vector>
    
    using namespace std;
    
    // This is just a function to print out a vector.
    template<typename T>
    inline ostream &operator<< (ostream &os, const vector<T> &v) {
        bool first = true;
        os << "(";
        for (int i = 0; i < v.size (); i++) {
            if (first) first = false;
            else os << " ";
            os << v[i];
        }
        return os << ")";
    }
    
    bool addOne (vector<int> &nums, int pos, int maxNum) {
        // If our position has moved off of bounds, so we're done
        if (pos < 0)
            return false;
    
        // If we have reached the maximum number in one column, we will
        // set it back to the base number and increment the next smallest number.
        if (nums[pos] == maxNum) {
            nums[pos] = 0;
            return addOne (nums, pos-1, maxNum);
        }
    
        // Otherwise we simply increment this numbers.
        else {
            nums[pos]++;
            return true;
        }
    }
    
    int main () {
        vector<int> nums;
        int spaces = 3;
        int numbers = 3;
    
        // populate all spaces with 0
        nums.resize (spaces, 0);
    
        // Continue looping until the recursive addOne() function returns false (which means we
        // have reached the end up all of the numbers)
        do {
            cout << nums << endl;    
        } while (addOne (nums, nums.size()-1, numbers));
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just saw this question and have no idea how to solve it. can
Can anyone give me some idea about uploading data from excel to access database
I'm studying programming on my own and I would like to have an idea
I have a little Bash script which suspends the computer after a given number
anyone have idea how to solve this problem counts the number of occurrences of
So, my idea is quite simple: print all of the possible combinations given X
To first give you an idea of what my HTML is like, I have
Just to give you a fair idea, I am new to the web development
Can someone please give me an idea of how the WIRED Magazine on iPad
Does anyone know of any resources that can give me an idea of how

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.