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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:00:23+00:00 2026-05-11T21:00:23+00:00

I’ve edited original text to save potential readers some time and health. Maybe someone

  • 0
  • I’ve edited original text to save potential readers some time and health. Maybe someone will actually use this.

I know it’s basic stuff. Probably like very, very basic.
How to get all possible combinations of given set.
E.g.
string set = “abc”;
I expect to get:
a b c aa ab ac aaa aab aac aba abb abc aca acb acc baa bab …
and the list goes on (if no limit for length is set).

I’m looking for a very clean code for that – all that I’ve found was kind of dirty and not working correctly. The same I can say about code I wrote.

I need such code because I’m writing brute force (md5) implementation working on multiple threads. The pattern is that there’s Parent process that feeds threads with chunks of their very own combinations, so they would work on these on their own.
Example: first thread gets package of 100 permutations, second gets next 100 etc.
Let me know if I should post the final program anywhere.

EDIT #2
Once again thank you guys.
Thanks to you I’ve finished my Slave/Master Brute-Force application implemented with MPICH2 (yep, can work under linux and windows across for example network) and since the day is almost over here, and I’ve already wasted a lot of time (and sun) I’ll proceed with my next task … 🙂
You shown me that StackOverflow community is awesome – thanks!

  • 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-11T21:00:24+00:00Added an answer on May 11, 2026 at 9:00 pm

    Here’s some C++ code that generates permutations of a power set up to a given length.

    The function getPowPerms takes a set of characters (as a vector of strings) and a maximum length, and returns a vector of permuted strings:

    #include <iostream>
    using std::cout;
    #include <string>
    using std::string;
    #include <vector>
    using std::vector;
    
    vector<string> getPowPerms( const vector<string>& set, unsigned length ) {
      if( length == 0 ) return vector<string>();
      if( length == 1 ) return set;
    
      vector<string> substrs = getPowPerms(set,length-1);
      vector<string> result = substrs;
      for( unsigned i = 0; i < substrs.size(); ++i ) {
        for( unsigned j = 0; j < set.size(); ++j ) {
          result.push_back( set[j] + substrs[i] );
        }
      }
    
      return result;
    }
    
    int main() {
      const int MAX_SIZE = 3;
      string str = "abc";
    
      vector<string> set;     // use vector for ease-of-access            
      for( unsigned i = 0; i < str.size(); ++i ) set.push_back( str.substr(i,1) );
    
      vector<string> perms = getPowPerms( set, MAX_SIZE );
      for( unsigned i = 0; i < perms.size(); ++i ) cout << perms[i] << '\n';
    }
    

    When run, this example prints

    a b c aa ba ca ab bb cb ... acc bcc ccc
    

    Update: I’m not sure if this is useful, but here is a “generator” function called next that creates the next item in the list given the current item.

    Perhaps you could generate the first N items and send them somewhere, then generate the next N items and send them somewhere else.

    string next( const string& cur, const string& set ) {
      string result = cur;
      bool carry = true;
      int loc = cur.size() - 1;
      char last = *set.rbegin(), first = *set.begin();
      while( loc >= 0 && carry ) {
        if( result[loc] != last ) {             // increment              
          int found = set.find(result[loc]); 
          if( found != string::npos && found < set.size()-1 ) {
            result[loc] = set.at(found+1); 
          }
          carry = false;
        } else {                                // reset and carry        
          result[loc] = first;
        }
        --loc;
      }
      if( carry ) {                             // overflow               
        result.insert( result.begin(), first );
      }
      return result;
    }
    
    int main() {
      string set = "abc";
      string cur = "a";
      for( int i = 0; i < 20; ++i ) {
        cout << cur << '\n';        // displays a b c aa ab ac ba bb bc ...
        cur = next( cur, set );
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.