I need to iterate over an ordered sequence that is defined by an array of numbers ai, i = 1..n, where n is the length of each sequence element, and each ai specifies the max number of possible values at position i in the output sequence.
Example:
a = {10,10,10}
Sequence:000
,001
,002
, ...999
(the decimal numbers from000
to999
)a = (2,3,2}
Sequence:000
,001
,010
,011
,020
,021
,100
,101
,110
,111
,120
,121
(Note: I don't just need to print the sequence, but I need to iterate over its elements, where each element is an array, e.g. {1,2,1}.)
Before I implement this, I wanted to ask if anyone has any comments? Maybe this is a known problem (name?), and there is already code available, or it reduces to some other well-known problem? It does have similarities to the permutation problem.