please help me to reverse a function call order

Test123 test123 at gmail.com
Sat Jul 23 19:50:51 UTC 2022


I has this function, it print all possible combinations.

```d
void doRepetition(const int n, const int m){
     // combination total number is m,  element is repeatable.
     assert(n >= 1 && n < 10);
     assert(m >= 1 && m < 10);
     enum N = 10;
     ubyte[10] a;
     void inc(int index, int r, int start, int end) {
         if( index == r ) {
             // get one unique combination result, not repeatable
             for(int j =0; j < r; j++ ){
                 printf("%d ", a[j]);
             }
             printf("\n");
             return ;
         }
         for (int i = start; i < end; i++) {
             a[index] = cast(ubyte)i;
             inc(index + 1, r, i, end);
         }
     }
     inc(0, m, 0, n);
}
```

`doRepetition(4, 3);` will print
```sh
0 0
0 1
0 2
1 1
1 2
2 2
```


I need one function,  print the number in reversed order like 
this:

`doReverseRepetition(4, 3);` will print
```sh
2 2
1 2
1 1
0 2
0 1
0 0
```

ont solution is to put the result in array, and foreach_reverse 
it.  but this is slow and need a lot memory when N, M is bigger. 
(9,9) will have 24310 restuls combinations. (I need support 
bigger N,M late and need it fast)

Any one can help me to write a function print the reversed order 
results?








More information about the Digitalmars-d-learn mailing list