First of all, your requirement example is wrong
because 'combinations' and 'permutations' also mean out of order
This means that 1324, 2341, 4321 ... are solutions too.
Quote:Is there a quick way?
Simpler than your code (assuming it is OK) : NO.
As you can see, your output is missing all results with a hole 124, 134, 13, 24 ...
You have to analyze which result is missing, understand why, and refine your code.
The debugger can help you.
I fear a complete rewrite is in order.
Hint for a possible Solution:
- make a loop that pick 1 digit at the time
- inside the loop print actual 1 digit number
- inside that loop, make a second loop that pick a second digit
- make sure it is not the same as first digit
- print number made of first and second digits