I’ve never been much for math and I’m hoping that someone can help me out with the following.
I have 5 boxes:
1 2 3 4 5 [ ] [ ] [ ] [ ] [ ]
The boxes can either be white, gray, or black (or think of it as 0, 1, 2)
How many possible states can the box set be in?
What is the pseudocode (or in any language) to generate all the possible outcomes??
ie…
00000 00001 00011 00111
etc, etc…
I really appreciate any help anyone can give me with this.
This is a classic permutation generation problem. You have 3 possibilities for each position, and 5 positions. The total number of generated string is 3^5 = 243. You need recursion if you want a general solution (a simple iterative loop only works for a single instance of the problem).
Here’s a quick example: