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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:13:05+00:00 2026-05-30T06:13:05+00:00

I am working on a problem in which I am given a number and

  • 0

I am working on a problem in which I am given a number and need to
find every possible permutation of the digits in that number. For
example, if I am given 20, the answer would be: 20 and 02. I know
that there are n! possible permutations, and I have divided up the
numbers so that each digit is an element in an array. My question is:
How can I loop through this array to generate every possible
combination of a number that is at least 2 digits long but no more
than 6.

  • 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-30T06:13:07+00:00Added an answer on May 30, 2026 at 6:13 am

    Say the n individual digits are in an array of length n. Then the problem of generating the permutations boils down to:

    1. Choosing one of the n digits as the first digit to print.
    2. Permuting the remaining n-1 digits.

    A recursion.

    The pseudocode for such a recursive function permute would be something like:

    List permute (Array digits)
    {
      List permutations = /* initialize an empty list */
    
      for (i=0; i<n; i++)
        {
          firstDigit = digit[i];
          Array otherDigits = /* array containing all digits except firstDigit.  */
          List subPermutations = permute(otherDigits);
          /* prepend firstDigit into each element of 'subPermutations' */
          /* add all elements of 'subPermutations' to the list 'permutations' */
        }
      return permutations;
    }
    

    Then simply call permute and print out the list, or do whatever else with it.

    EDIT: You also need to handle the edge case of permuteing 1 digit.

    I think this is already too much information for ‘homework’ 🙂

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

Sidebar

Related Questions

I am working on a problem which was given to me by my friend.
i've been working on a problem for a while now, which involves targeting the
Real problem with an existing webapp which has been working for the last couple
Problem When working with MasterPages, a common irritation I run into is that script
I'm working on a problem that requires caching paginated search results: Paginating very large
I'm working on a problem where I need to store serialized hierarchies of Ruby
I'm working on an app in which I need to scan through a string
I am trying to reverse order of given numbers in python.The problem says that
I am working on a program which needs to cube a number. Long story
I'm working on a Project Euler problem which requires factorization of an integer. I

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.