I'm trying to find all possible combinations of numbers.

for example: Input 1 2 3 4 5

Output 
1,
2,
3,
4,
5,
21,
31,
32,
41,
42,
43,
51,
52,
53,
54,
321,
421,
431,
432,
521,
531,
532,
541,
542,
543,
4321,
5321,
5421,
5431,
5432,
54321

(every number should be this ordered - from biggest to lowest) 

I have an sorted array. I'm trying to write these numbers, it works perfectly fine but input with multiple same numbers like 3 3 2 2 1 not working good.

Bad thing is, that this needs recursion.

my base algorithm looks like this: (its more complicated but this is base structure)

```
extract(arrWithNumbers, PrintingArray) {

    For(i = 0; 0 < Numbers in array; i++) {
        if (numbers == i + 1) print(PrintingArray);
        PrintingArray[i] = arrWithNumbers[i];
        extract(arrWithNumbers, PrintingArray);
    }
}

```

Is there any known algorithm that can help me?

It's not only finding all possible combinations using 

![Combination formula](https://i.stack.imgur.com/QRKCe.png)

Thanks, for time and help.