I have an array of integers: n[]
.
Also, I have an array (Nr[]
) contains n.length
integers. I need to generate all combinations of n[]
in a following way:
/* let n.length == 3 and Nr[0] = 2, Nr[1] = 3, Nr[2] = 3 */
n = {0, 0, 0};
n = {1, 0, 0};
n = {2, 0, 0};
n = {0, 1, 0};
n = {0, 2, 0};
n = {0, 3, 0};
n = {0, 0, 1};
...
n = {1, 1, 0};
n = {1, 2, 0};
n = {1, 3, 0};
n = {2, 1, 0};
n = {2, 2, 0};
n = {2, 3, 0};
n = {1, 1, 1};
...
n = {0, 1, 1};
// many others
The goal is to find all combinations of n
, where n[i]
can be 0 to Nr[i]
.
I did not succeed... How to solve it in Java? Or not in Java...
See Question&Answers more detail:os