## Saturday, 11 July 2009

### for looping to infinity

I've an a 2-dimensional array that is best represented in the following tables; it has an arbitrary number of "columns" but only ever 4 "rows".

I need to produce the following "Possible" results programmatically.

```+-+     Possible: a, A, x, X
|a|               (4 * 1 = 4 possibles)
+-+
|A|
+-+
|x|
+-+
|X|
+-+

+-+-+   Possible: ab, aB, aX, aY, Ab, AB, AX, AY,
|a|b|             xb, xB, xX, xY, Xb, XB, XX, XY
+-+-+             (4 * 4 = 16 possibles)
|A|B|
+-+-+
|x|y|
+-+-+
|X|Y|
+-+-+

+-+-+-+ Possible: abc, abC, abz, abZ, aBc, aBC, aBz, aBZ,
|a|b|c|           ayc, ayC, ayz, ayZ, aYc, aYC, aYz, aYZ,
+-+-+-+           Abc, AbC, Abz, AbZ, ABc, ABC, ABz, ABZ,
|A|B|C|           Ayc, AyC, Ayz, AyZ, AYc, AYC, AYz, AYZ,
+-+-+-+           xbc, xbC, xbz, xbZ, xBc, xBC, xBz, xBZ,
|x|y|z|           xyc, xyC, xyz, xyZ, xYc, xYC, xYz, xYZ,
+-+-+-+           Xbc, XbC, Xbz, XbZ, XBc, XBC, XBz, XBZ,
|X|Y|Z|           Xyc, XyC, Xyz, XyZ, XYc, XYC, XYz, XYZ
+-+-+-+           (16 * 4 = 64 possibles)```

I've been trying this now for about 2 days and I think about it and think about it and finally think I've got there but then try it out and it crashes and burns... I've tried rotating the array as well to no joy (perhaps that warrants further investigation?)

Help solicited here.