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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:27:17+00:00 2026-05-28T16:27:17+00:00

Consider number 194 declared as type int Is it possible to obtain it’s digits

  • 0

Consider number 194 declared as type int
Is it possible to obtain it’s digits permutations like other ints efficiently?
Number: 194
419 int
491 int
914 int
941 int

I am using the next_permutation however it only works with arrays. So I thought it wouldn’t be wise to convert int to an int array (?!) then obtain the permutation as an array and convert it to it.

Any suggestions?

  • 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-28T16:27:17+00:00Added an answer on May 28, 2026 at 4:27 pm

    Permuting the digits is basically a string-operation, not a (simple) mathematical operation. Converting to an array (string) and then using next_permutation() sounds more sensible than trying to do it mathematically.

    Here’s the mathematical version – without intermediate values saved:

    int a = 194;
    int b = (a / 100)       * 100 + (a % 10)        * 10 + ((a / 10) % 10) * 1; // 149
    int c = (a % 10)        * 100 + ((a / 10) % 10) * 10 + (a / 100)       * 1; // 491
    int d = (a % 10)        * 100 + (a / 100)       * 10 + ((a / 10) % 10) * 1; // 419
    int e = ((a / 10) % 10) * 100 + (a / 100)       * 10 + (a % 10)        * 1; // 914
    int f = ((a / 10) % 10) * 100 + (a % 10)        * 10 + (a / 100)       * 1; // 941
    

    With intermediate values, it’s a little easier to see what’s going on (except that I generated different assignments for b through f this time).

    int a = 194;
    int d1 = a / 100;
    int d2 = (a / 10) % 10;
    int d3 = a % 10;
    
    int a = d1 * 100 + d2 * 10 + d3 * 1; // 194
    int b = d1 * 100 + d3 * 10 + d2 * 1; // 149
    int c = d2 * 100 + d1 * 10 + d3 * 1; // 914
    int d = d2 * 100 + d3 * 10 + d1 * 1; // 941
    int e = d3 * 100 + d1 * 10 + d2 * 1; // 419
    int f = d3 * 100 + d2 * 10 + d1 * 1; // 491
    

    Use the next_permutation() mechanism; it will generalize to 4-digit and 5-digit and N-digit numbers where this will not.

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

Sidebar

Related Questions

Consider the following table: mysql> select * from phone_numbers; +-------------+------+-----------+ | number | type
What's the longest possible worldwide phone number I should consider in SQL varchar(length) for
Consider a variable length string starting with a variable number of digits, then a
Consider an ASP.NET server control DropDownList (or <input type='select'> ) with a large number
Consider a simple Enumerator like this: natural_numbers = Enumerator.new do |yielder| number = 1
Consider the following snippet of code: // get number of sheep in DataTable by
Consider I have a data grid, I need to find the number of rows
Consider this regex: ^([0-9]+)(?: ([-\+/%\*]) ([0-9]+))+$ In english, it says a number, followed by
Consider two dates 2010-03-18 22:30:45 and 2010-03-19 03:30:15 .... How to get the number
Consider the following code: List<double> l = new List<double>(); //add unknown number of values

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.