I need to create an n-dimensional matrix containing all possible combinations of items from an arbitrarily sized list of arrays, in a generic way that can handle arbitrary sizes of both the list of "dimensions" and the number of values in each dimension.

For example, say my program is fed with this input:

```
type: d4, d6, d8, d12, d20
color: red, blue, golden

```

Then I will need to generate the following list of items:

```
red d4, red d6, red d8, red d12, red d20, blue d6, blue d8, blue d12, blue d20,
golden d4, golden d6, golden d8, golden d12, golden d20

```

I initially had a static code that works for two dimensions, but now I need to solve for 1~n dimensions.

Any standard programming language will do (i.e. please don't use magical functional languages that I will have no idea how to translate to my implementation), and even a free language description. Much appreciated.