Here is a question for more elegant programming:
pj = {j - 1, j, j + 1}
pi = {i - 1, i, i + 1}
pk = {k - 1, k, k + 1}
I want to combine these three lists which have three elements each, in such a way that each element of one list is combined with one element of all remaining lists. When I use Partition, Flatten and Table Commands, the result looks like
pt = Partition[
Flatten[Table[{i + (u1 - 2), j + (u2 - 2), k + (u3 - 2)}, {u1, 1,
3}, {u2, 1, 3}, {u3, 1, 3}]], 3]
{{-1 + i, -1 + j, -1 + k}, {-1 + i, -1 + j, k}, {-1 + i, -1 + j,
1 + k}, {-1 + i, j, -1 + k}, {-1 + i, j, k}, {-1 + i, j,
1 + k}, {-1 + i, 1 + j, -1 + k}, {-1 + i, 1 + j, k}, {-1 + i, 1 + j,
1 + k}, {i, -1 + j, -1 + k}, {i, -1 + j, k}, {i, -1 + j,
1 + k}, {i, j, -1 + k}, {i, j, k}, {i, j, 1 + k}, {i,
1 + j, -1 + k}, {i, 1 + j, k}, {i, 1 + j,
1 + k}, {1 + i, -1 + j, -1 + k}, {1 + i, -1 + j, k}, {1 + i, -1 + j,
1 + k}, {1 + i, j, -1 + k}, {1 + i, j, k}, {1 + i, j,
1 + k}, {1 + i, 1 + j, -1 + k}, {1 + i, 1 + j, k}, {1 + i, 1 + j,
1 + k}}
Length[pt]
27
Now, I want to combine n lists (p1, p2, ..., pn), which have three elements each in the way described above. The resulting list is a {3^n, n} matrix. I am looking for an elegant solution.
Best,
GG