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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:06:28+00:00 2026-05-10T22:06:28+00:00

I need a function count_permutations() that returns the number of permutations of a given

  • 0

I need a function count_permutations() that returns the number of permutations of a given range. Assuming that the range is allowed to be modified, and starts at the first permutation, I could naively implement this as repeated calls to next_permutation() as below:

template<class Ret, class Iter> Ret count_permutations(Iter first, Iter last) {     Ret ret = 0;     do {         ++ret;     } while (next_permutation(first, last));     return ret; } 

Is there a faster way that doesn’t require iterating through all the permutations to find the answer? It could still assume that the input can be modified, and starts in the first permutation, but obviously if it is possible to implement without those assumtions it’d be great too.

  • 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. 2026-05-10T22:06:29+00:00Added an answer on May 10, 2026 at 10:06 pm

    The number of permutations for a range where all the elements are unique is n! where n is the length of the range.

    If there are duplicate elements, you can use n!/(n_0!)…(n_m!) where n_0…n_m are the lengths of duplicate ranges.

    So for example [1,2,3] has 3! = 6 permutations while [1,2,2] has 3!/2! = 3 permutations.

    EDIT: A better example is [1,2,2,3,3,3] which has 6!/2!3! = 60 permutations.

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

Sidebar

Related Questions

I need a function that for a given R,G,B values returns the next color.
I have a riddle for you. I need a function that displays the number
I need function count_sprintf() that should return number of characters (not inc nul byte)
I need a function that could generate a regex. For example if I write
I need the function to repeat after 8 seconds the first time and then
I need a function that can intersect 2 arrays for example: $Array1 = array(1,2,3);
I need a function that can print Turkish characters. public String convert(String input) {
I need a function which returns true if the certificate of a secure website
I need a function like var_dump($object) in php The problem is that the Var_dump
I want to write a function that reads a file and counts the number

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.