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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:47:23+00:00 2026-05-28T17:47:23+00:00

I’m trying to efficiently list numbers between 1 and 100. However I have to

  • 0

I’m trying to efficiently list numbers between 1 and 100. However I have to get rid of numbers with same digits.
Example:
12 according to this rule is the same of 21
13 is 31
14 is 41
so the for loop it won’t go over the same numbers.
I’m thinking a few tricks such as getting all the numbers from 1 to 100 and then deleting the found permutations of current number.
The reason I’m asking this because in large limits like 100000 it will fail.
Another example: 124 is equal to 142,241,214,412,421

  • 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-28T17:47:25+00:00Added an answer on May 28, 2026 at 5:47 pm

    You can apply recursion. Prototype of this function is then like:

    print_digits(int num_of_remaining_digits,int start_from_digit, int current_number);
    

    EDIT: for completion I present here my solution (i think it has better readbility than from Ben Voigt and ascending output order

    void print_digits(int num_of_remaining_digits,int start_from_digit, int current_number)
    {
      if(num_of_remaining_digits == 0) 
      {
        std::cout << current_number << std::endl;
        return;
      }
    
      for(int i=start_from_digit;i<=9;i++)
      {
         print_digits(num_of_remaining_digits-1,i,10*current_number+i);
      }
    }
    

    and here is testing code

    http://ideone.com/Xm8Mv

    How this works?

    It is one of classics in recursion. First there is stopping condition. And then there is main loop.
    Main loop where goes from start_from_digit because all generated digits will be in non decreasing order. For instance if current_number is 15 it will call print_digits whith

    print_digits(num_of_remaining_digits-1,5,155)
    print_digits(num_of_remaining_digits-1,6,156)
    print_digits(num_of_remaining_digits-1,7,157)
    print_digits(num_of_remaining_digits-1,8,158)
    print_digits(num_of_remaining_digits-1,9,159)
    

    In each call it will check if we reached end whit num_of_remaining_digits and if not will continue from digit that is pushed as start_from_digit (2nd param) using current_number

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.