combination digits "12345"

how many times a combination digits "12345" appear in the range of 0 to 50000???? is this posible?
I think you need to find out combination like "12345", "21345" "32145" etc
we can convert the number to a string and then compare each character
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<sstream>
#include<iostream>
using namespace std;
int main(){
	size_t found;
	for(int i=12345; i<50000; i++){
		
		ostringstream s;
		s<<i;
		string mystring=s.str();
		found=mystring.find('1');
		if (found==string::npos){
			continue;
		}
		found=mystring.find('2');
		if (found==string::npos){
			continue;
		}
		found=mystring.find('3');
		if (found==string::npos){
			continue;
		}
		found=mystring.find('4');
		if (found==string::npos){
			continue;
		}
		found=mystring.find('5');
		if (found==string::npos){
			continue;
		}
		
		cout<< mystring << "\n";
	}
	return 0;
}
It is 4*4*3*2*1 or 96 possibilities.

Why? You can have four possible digits for the first digit because if the first one would be a five, the result would be > 50,000.
Then, the second digit can be any digit from the remaining 4, then from the remaining three, two and the last one.

I do not know if the english term is FACULTY but in mathematics it is written as 4 * 4!

Hope that helps.

int main

Yes, if you just want the total number it is 4* 4!=96
! is called factorial, if you put a counter in the program it will show 96 at the end.
Topic archived. No new replies allowed.