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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:42:46+00:00 2026-06-15T00:42:46+00:00

I am using permutation to generate a string (using each of its character) into

  • 0

I am using permutation to generate a string (using each of its character) into “helloworld!”, however it took…176791 to get to “helloworld!” Is there a ways so I can just input: 176791 to quickly permutate to “helloworld!”?

        ...
176790. helloworl!d
176791. helloworld!

My code:

#include <windows.h>
#include <string>
#include <iostream>
#include <algorithm>

int main( void )
{
    ::UINT64 Count = 0;
    std::string SomeString = "eohldo!lwrl";
    do
    {
        Count ++;
        std::cout << Count << ". " << SomeString << std::endl;
        if( SomeString == "helloworld!" )
            break;
    } while( std::next_permutation( SomeString.begin( ), SomeString.end( ) ) );

    ::getchar( );
    return( 0 );
};
  • 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-15T00:42:47+00:00Added an answer on June 15, 2026 at 12:42 am

    I’m not sure what the question is about. Basically, it looks like you are looking for a way to “encode” a permutation by an integer. But it is not clear whether this encoding is required to be synchronized with permutation sequence generated by sequential calls to std::next_permutation. Is it? I.e do you require that number 176791 encodes a permutation produced by 176791 applications of std::next_permutation?

    Permutations can be encoded by integers in several different ways. Properly constructed encodings will all occupy the same number of bits. But different encodings will might use different integers to encode the same permutation.

    Anyway, if you don’t care about a specific encoding method, then any permutation for N elements can be encoded in the following manner:

    • Imagine the canonical representation of the permutation: an array of N indexes that describe the new positions of the sequence’s elements, i.e. index[old position] = new position.

    • Now simply interpret that array as a N-digit number in base N. I.e. the permutation is represented by an integer value

      index[0]*N^0 +  index[1]*N^1 + index[2]*N^2 + ... + index[N-1]*N^(N-1)
      

    Basically, the canonical array representation of the original permutation is packed into a sufficiently large integer value. (If N is a power of 2, this representation will simply pack the original array values into a bit-array). Both packing and unpacking is a straightforward process.

    Unfortunately, the representation I describe above is not well-constructed. It requires more bits than necessary, since it attempts to “losslessly” encode index arrays with non-unique values. A valid representation of a permutation will not have repetitive values in the index array. This immediately means that the above representation is excessive. A more compact representation should be possible. Anyway, this should be a rather well-researched subject and a simple Google search should turn up lots of information on encoding permutations.


    Here’s a SO link that offers a much deeper analysis of this topic

    Fast permutation -> number -> permutation mapping algorithms

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to generate all permutation of a string with selecting some of the
I am using this code to generate a random permutation of a vector using
I know you can generate all permutations from a list, using glob or Algorithm::Permute
I'm trying to construct a permutation program in Perl using the NestedLoops function. Here's
Using the Redis info command, I am able to get all the stats of
Using Location.getBearing(); I seem to get randomly changing bearings. Aka, I can turn the
I'm using Ruby and needed to somehow generate all permutations of the digits in
I'm trying to generate multiple permutations using this code: :- use_module(library(clpfd)). p(N, Indexes) :-
I need to generate permutations from multiple ranges of numbers in array. using namespace
I think I have a complex requirement. It's a combinatorial permutation using Oracle 10.2,

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.