please help me to reverse a function call order

Salih Dincer salihdb at hotmail.com
Sat Jul 23 22:50:55 UTC 2022


On Saturday, 23 July 2022 at 19:50:51 UTC, Test123 wrote:
> 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.
>     // ...
> }
> ```
>
> `doRepetition(4, 3);` will print
>
> 0 0
> 0 1
> 0 2
> 1 1
> 1 2
> 2 2

Do I misunderstand? In function parameters, m is a base, n is a 
power; is it true?

If so, it is calculated according to the formula 2ⁿ as we know 
between 0 and 1, but here m can be larger. Then there are 64 
possibilities for doRepetition(3, 6) But your code has 28 
possibilities, I guess I didn't read the code correctly.

**My code outputs:**

```
[0, 0, 0, 0, 0, 0, 0, 0]: 1
[0, 0, 0, 0, 0, 0, 0, 1]: 2
[0, 0, 0, 0, 0, 0, 1, 0]: 3
[0, 0, 0, 0, 0, 0, 2, 1]: 4
[0, 0, 0, 0, 0, 1, 1, 0]: 5
[0, 0, 0, 0, 0, 2, 0, 1]: 6
[0, 0, 0, 0, 0, 2, 1, 0]: 7
[0, 0, 0, 0, 0, 2, 2, 1]: 8
[0, 0, 0, 0, 1, 1, 1, 0]: 9
[0, 0, 0, 0, 2, 0, 0, 1]: 10
[0, 0, 0, 0, 2, 0, 1, 0]: 11
[0, 0, 0, 0, 2, 0, 2, 1]: 12
[0, 0, 0, 0, 2, 1, 1, 0]: 13
[0, 0, 0, 0, 2, 2, 0, 1]: 14
[0, 0, 0, 0, 2, 2, 1, 0]: 15
[0, 0, 0, 0, 2, 2, 2, 1]: 16
[0, 0, 0, 1, 1, 1, 1, 0]: 17
[0, 0, 0, 2, 0, 0, 0, 1]: 18
[0, 0, 0, 2, 0, 0, 1, 0]: 19
[0, 0, 0, 2, 0, 0, 2, 1]: 20
[0, 0, 0, 2, 0, 1, 1, 0]: 21
[0, 0, 0, 2, 0, 2, 0, 1]: 22
[0, 0, 0, 2, 0, 2, 1, 0]: 23
[0, 0, 0, 2, 0, 2, 2, 1]: 24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