Skip to main content
2 of 5
Add iteratedTable function
Carl Woll
  • 132.7k
  • 6
  • 253
  • 366

Maybe you could do something like:

X = 3; Y = 5; Table[l[i] = Indexed[g, i], {i, X}]; Table[{l[1], l[3]}, {g, Subsets[Range[Y],{X}]}] 

{{1, 3}, {1, 4}, {1, 5}, {1, 4}, {1, 5}, {1, 5}, {2, 4}, {2, 5}, {2, 5}, {3, 5}}

You could create a function to do this:

SetAttributes[iterateTable,HoldAll] iteratedTable[e_, g_Symbol, iterations_, max_] := Block[{g = Indexed[\[FormalL], #]&}, Table[e, {\[FormalL], Subsets[Range@max, {iterations}]}] ] 

Example:

iteratedTable[h[l[1], l[3], l[2]], l, 3, 5] 

{h[1, 3, 2], h[1, 4, 2], h[1, 5, 2], h[1, 4, 3], h[1, 5, 3], h[1, 5, 4], h[2, 4, 3], h[2, 5, 3], h[2, 5, 4], h[3, 5, 4]}

Carl Woll
  • 132.7k
  • 6
  • 253
  • 366