title: Finding every combination of elements in a table (Lua/PseudoCode)
body: <p>I'm trying to execute a function with every single combination of elements from a table.  (In Lua).  The table and the elements can change, but the structure will stay the same.  The table is organized so that [1] of it would be the first argument of the function, and so on and so on.</p>
  
  <p>If this is a table that I've got, </p>
  
  <pre><code>Table = {
      [1] = {Player1, Player2}
      [2] = {PlayerA, PlayerB, PlayerC}
      [3] = {PlayerOne, PlayerTwo}
  }
  </code></pre>
  
  <p>If I wrote that out manually, it would probably look like this: (Given that the function is named Exe).</p>
  
  <pre><code>Exe(Player1, PlayerA, PlayerOne)
  Exe(Player2, PlayerA, PlayerOne)
  Exe(Player3, PlayerA, PlayerOne)
  
  Exe(Player1, PlayerB, PlayerOne)
  Exe(Player2, PlayerB, PlayerOne)
  Exe(Player3, PlayerB, PlayerOne)
  
  Exe(Player1, PlayerC, PlayerOne)
  Exe(Player2, PlayerC, PlayerOne)
  Exe(Player3, PlayerC, PlayerOne)
  
  
  Exe(Player1, PlayerA, PlayerTwo)
  Exe(Player2, PlayerA, PlayerTwo)
  Exe(Player3, PlayerA, PlayerTwo)
  
  Exe(Player1, PlayerB, PlayerTwo)
  Exe(Player2, PlayerB, PlayerTwo)
  Exe(Player3, PlayerB, PlayerTwo)
  
  Exe(Player1, PlayerC, PlayerTwo)
  Exe(Player2, PlayerC, PlayerTwo)
  Exe(Player3, PlayerC, PlayerTwo)
  </code></pre>
  
  <p>However, I don't WANT to write that out, and it breaks my general rule of thumb that if you're copying and pasting in a program, you're doing it wrong.</p>
  
  <p>So instead, I would like to go through the table and execute every single possible combination.  The problem so that the table can (potentially) have any number of tables inside of it, and also that the table inside of the table can potentially have unlimited number of values.  </p>
  
  <p>For example, the table could end up looking like this:</p>
  
  <pre><code>Table = {
      [1] = {Player1, Player2}
      [2] = {PlayerA}
      [3] = {PlayerOne}
  }
  </code></pre>
  
  <p>In which execution would end up looking like this manually:</p>
  
  <pre><code>Exe(Player1, PlayerA, PlayerOne)
  Exe(Player2, PlayerA, PlayerOne)
  </code></pre>
  
  <p>Also, the table might end up like this:</p>
  
  <pre><code>Table = {
      [1] = {Player1, Player2}
      [2] = {PlayerA}
      [3] = {PlayerOne}
      [4] = {PlayerUno, PlayerDos}
      [5] = {PlayerApple, PlayerBoy, PlayerCat, PlayerDog}
  }
  </code></pre>
  
  <p>In which the exeuction would end up like..</p>
  
  <pre><code>Exe(Player1, PlayerA, PlayerOne, PlayerUno, PlayerApple)
  Exe(Player2, PlayerA, PlayerOne, PlayerUno, PlayerApple)
  
  Exe(Player1, PlayerA, PlayerOne, PlayerDos, PlayerApple)
  Exe(Player2, PlayerA, PlayerOne, PlayerDos, PlayerApple)
  
  
  Exe(Player1, PlayerA, PlayerOne, PlayerUno, PlayerBoy)
  Exe(Player2, PlayerA, PlayerOne, PlayerUno, PlayerBoy)
  
  Exe(Player1, PlayerA, PlayerOne, PlayerDos, PlayerBoy)
  Exe(Player2, PlayerA, PlayerOne, PlayerDos, PlayerBoy)
  
  
  Exe(Player1, PlayerA, PlayerOne, PlayerUno, PlayerCat)
  Exe(Player2, PlayerA, PlayerOne, PlayerUno, PlayerCat)
  
  Exe(Player1, PlayerA, PlayerOne, PlayerDos, PlayerCat)
  Exe(Player2, PlayerA, PlayerOne, PlayerDos, PlayerCat)
  
  
  Exe(Player1, PlayerA, PlayerOne, PlayerUno, PlayerDog)
  Exe(Player2, PlayerA, PlayerOne, PlayerUno, PlayerDog)
  
  Exe(Player1, PlayerA, PlayerOne, PlayerDos, PlayerDog)
  Exe(Player2, PlayerA, PlayerOne, PlayerDos, PlayerDog)
  </code></pre>
  
  <p>As you can see, I have found a pattern...  I was able to divide the above 'Execution' thing above into segments/groups, such as line 1 and line 2  have one change.  Then, they get copied into line 4 and 5, but the next variable get's changed.  </p>
  
  <p>As you can see, I'm having trouble putting that pattern into code.  I think some function recursion will be required, but I'm not sure how to pull it off or recurse through it.  I'm thinking that I'll have to use functions with ... as the arguments, and the unpack function, but I'm not sure how this would even work.  </p>
  
  <p>Also, the reason this is required, and not just manually copying and pasting it (Which actually would be easier), is because the content of the table will be generated.</p>
  
  <p>Can you guys help me? </p>