I am trying to explicitly write out the sample space for a variable number of components. The function would take a list as an input that provided the number of settings available to each component. A few examples to clarify what I am trying to do:
A={2,1,1} (*three components, the first has potential settings of 0,1,2, the second and third each have possible settings of 0 and 1*)
B={3,2} (*two components; the first with 0,1,2,3 the second with 0,1,2 as settings *)
C={1,1,1,1} (*four components; all have settings of 0 and1*)
Output using A:
{{0,0,0},{0,1,0},{0,0,1},{0,1,1},
{1,0,0},{1,1,0},{1,0,1},{1,1,1},
{2,0,0},{2,1,0},{2,0,1},{2,1,1}}
Output using B:
{{0,0},{0,1},{0,2},
{1,0},{1,1},{1,2},
{2,0},{2,1},{2,2},
{3,0},{3,1},{3,2}}
Output using C:
{{0,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1},{0,1,1,0},{0,1,0,1},{0,0,1,1},{0,1,1,1},
{1,0,0,0},{1,1,0,0},{1,0,1,0},{1,0,0,1},{1,1,1,0},{1,1,0,1},{1,0,1,1},{1,1,1,1}}
If I knew the number of components in advance, I could write a set of nested for loops that will do this. Unfortunately, I do not know the number of components in advance. So, I need something a little more flexible. Unfortunately, it seems to exceed my abilities. Any assistance would be helpful.
If it makes any difference when there are different numbers of settings for components they will always be listed in order of decreasing number of settings, i.e. {3,2,1} never {1,2,3}.