Need help with algorithm assignment

There are 9 digit in the range of 1234566789 to 987654321 where each digit apear only once. Write a program that write 100 000th number in these sequence.
The first number is 123456789
The second number is 123456798
The third number is 123456879
No digit can repeat so 122345675 is not a valid number in this sequence.

This is the assignment. Please help!
Actually I don't fully understand the assignment, I was hoping someone could break it down for me and give me some tips or hints.
I think it might be something like this(not completely sure though).
1
2
3
4
5
6
7
8
9
10
123,456,789

123,456,798

123,456,879
123,456,897

123,457,689
123,457,869
123,457,896


Note the highlighted digit's position relative to the first number. The highlighted digit seems to move forward until it's at the end. That is, it swaps places with the next digit.

I've coded a prototype of my hypothesis and it seems to work.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;

int main( )
{
    const string num{ "123456789" }; const size_t len{ num.length( ) };
    
    cout << num << "\n\n";
    for( size_t i{}; i < len - 1; i++ ) {
        
        string temp{ num };
        for( size_t j{}; j < i + 1; j++ ) {
            swap( temp[len-i-2 + j], temp[len-i-1 + j] );
            cout << temp << '\n';
            cout << setw( len-i + j + 1 ) << "^\n";
        }
        cout << '\n';
    }
}

123456789

123456798
        ^

123456879
       ^
123456897
        ^

123457689
      ^
123457869
       ^
123457896
        ^

123465789
     ^
123467589
      ^
123467859
       ^
123467895
        ^

123546789
    ^
123564789
     ^
123567489
      ^
123567849
       ^
123567894
        ^

124356789
   ^
124536789
    ^
124563789
     ^
124567389
      ^
124567839
       ^
124567893
        ^

132456789
  ^
134256789
   ^
134526789
    ^
134562789
     ^
134567289
      ^
134567829
       ^
134567892
        ^

213456789
 ^
231456789
  ^
234156789
   ^
234516789
    ^
234561789
     ^
234567189
      ^
234567819
       ^
234567891
        ^
Last edited on
I think the sequence is just the legitimate numbers in ascending order of size.

It appears to be here:
https://github.com/charleskorn/one-hundred-thousandth-number
Topic archived. No new replies allowed.