write all possible values of an array

Jun 18, 2016 at 8:52pm
What is an elegant way to write all possible values of an array? Let's say that the array is boolean:

bool A[3];

I'm trying to generate all possible values of this array: (0,0,0), (0,1,0), (0,0,1), (0,1,1), (1,0,0), (1,1,0), (1,0,1), (1,1,1). (Permutations with replacement, I believe)

Obviously, the number of possible values is K^n, where K is the number of possible values for each member of the array (2 for boolean, 10 for digits, etc.), and n is the length of the array. How do I make sure I cover all of them?
Last edited on Jun 18, 2016 at 9:05pm
Jun 19, 2016 at 12:51am
The algorithm library has methods for generating permutations.
Specifically the example given here http://www.cplusplus.com/reference/algorithm/next_permutation/
Jun 19, 2016 at 6:14am
This isn't a permutation, though. It's treating an array as a number and iterating through all its possible states.
Topic archived. No new replies allowed.