title: How to list all permutations without repetition?
body: <p>The current post is a follow-up question to this linked one:</p>
  <p><a href="https://stackoverflow.com/questions/73739554/shuffle-a-deck-of-7-hypothetical-trading-cards-and-list-out-the-orders-they-can">Shuffle a deck of 7 hypothetical trading cards and list out the orders they can come in a Google Sheet</a></p>
  <p>Surprise! My problem child is actually for Shin Megami Tensei 3 permutations -- for a video game. I thought putting it into terms of trading cards would make more sense to the layman. Forgive me.</p>
  <p><a href="https://i.stack.imgur.com/gOUJE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gOUJE.png" alt="Big Permutations... Now Handle It!!!" /></a></p>
  <p>Okay. I messed around with a data set of 7 unique monsters (an initial set that's easy to obtain early in the video game). They can't be duplicated in my party but can be combined to make different ones. At the start, there are just 8 slots available for monsters in the video game.</p>
  <p>This project focuses on building all the permutations of a &quot;fusion chain&quot; that attempts to take these monsters and arrange them into unique orders for a later combination within this chain.</p>
  <p>It starts with A+B and then cleans that list to eliminate any B+A scenarios from the initial pairings (fusing A+B or B+A makes the same result). Then, the fusions just tack on C, D, E, F, G, and H (currently broken) to the result of the previous fusion until no more possible fusions remain (having only a single monster in my party).</p>
  <p>The problem is this: the query or other functions within the permutation cell throw the error &quot;The resulting array was too large&quot; when attempting to list permutations for sorting 8 monsters at once -- even before the fusions can happen. I have isolated the issue to this formula (a bit long):</p>
  <pre><code>=iferror(if(counta($A$2:$A$13)&gt;=2,arrayformula(query(query(split(flatten(flatten(flatten(flatten(flatten(flatten(
  filter($F$2:$F,$F$2:$F&lt;&gt;&quot;&quot;)&amp;if(counta($A$2:$A$13)&gt;=3,&quot;,&quot;&amp;transpose(
  filter($A$2:$A$13,$A$2:$A$13&lt;&gt;&quot;&quot;)),&quot;&quot;))&amp;if(counta($A$2:$A$13)&gt;=4,&quot;,&quot;&amp;transpose(
  filter($A$2:$A$13,$A$2:$A$13&lt;&gt;&quot;&quot;)),&quot;&quot;))&amp;if(counta($A$2:$A$13)&gt;=5,&quot;,&quot;&amp;transpose(
  filter($A$2:$A$13,$A$2:$A$13&lt;&gt;&quot;&quot;)),&quot;&quot;))&amp;if(counta($A$2:$A$13)&gt;=6,&quot;,&quot;&amp;transpose(
  filter($A$2:$A$13,$A$2:$A$13&lt;&gt;&quot;&quot;)),&quot;&quot;))&amp;if(counta($A$2:$A$13)&gt;=7,&quot;,&quot;&amp;transpose(
  filter($A$2:$A$13,$A$2:$A$13&lt;&gt;&quot;&quot;)),&quot;&quot;))&amp;if(counta($A$2:$A$13)&gt;=8,&quot;,&quot;&amp;transpose(
  filter($A$2:$A$13,$A$2:$A$13&lt;&gt;&quot;&quot;)),&quot;&quot;)),&quot;,&quot;),
  &quot;where Col1 &lt;&gt; Col2&quot;&amp;
  if(counta($A$2:$A$13)&gt;=3,&quot; and Col1 &lt;&gt; Col3 and Col2 &lt;&gt; Col3&quot;&amp;
  if(counta($A$2:$A$13)&gt;=4,&quot; and Col1 &lt;&gt; Col4 and Col2 &lt;&gt; Col4 and Col3 &lt;&gt; Col4&quot;&amp;
  if(counta($A$2:$A$13)&gt;=5,&quot; and Col1 &lt;&gt; Col5 and Col2 &lt;&gt; Col5 and Col3 &lt;&gt; Col5 and Col4 &lt;&gt; Col5&quot;&amp;
  if(counta($A$2:$A$13)&gt;=6,&quot; and Col1 &lt;&gt; Col6 and Col2 &lt;&gt; Col6 and Col3 &lt;&gt; Col6 and Col4 &lt;&gt; Col6 and Col5 &lt;&gt; Col6&quot;&amp;
  if(counta($A$2:$A$13)&gt;=7,&quot; and Col1 &lt;&gt; Col7 and Col2 &lt;&gt; Col7 and Col3 &lt;&gt; Col7 and Col4 &lt;&gt; Col7 and Col5 &lt;&gt; Col7 and Col6 &lt;&gt; Col7&quot;&amp;
  if(counta($A$2:$A$13)&gt;=8,&quot; and Col1 &lt;&gt; Col8 and Col2 &lt;&gt; Col8 and Col3 &lt;&gt; Col8 and Col4 &lt;&gt; Col8 and Col5 &lt;&gt; Col8 and Col6 &lt;&gt; Col8 and Col7 &lt;&gt; Col8&quot;,),),),),),),0),&quot;where Col1 &lt;&gt;''&quot;,0)),&quot;not enough data&quot;),)
  </code></pre>
  <p>And the first range this formula was looking at is here in its previously stable form (column F):</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>unique init pairs</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Pixie,Shikigami</td>
  </tr>
  <tr>
  <td>Kodama,Pixie</td>
  </tr>
  <tr>
  <td>Hua Po,Pixie</td>
  </tr>
  <tr>
  <td>Datsue-Ba,Pixie</td>
  </tr>
  <tr>
  <td>Angel,Pixie</td>
  </tr>
  <tr>
  <td>Fomorian,Pixie</td>
  </tr>
  <tr>
  <td>Kodama,Shikigami</td>
  </tr>
  <tr>
  <td>Hua Po,Shikigami</td>
  </tr>
  <tr>
  <td>Datsue-Ba,Shikigami</td>
  </tr>
  <tr>
  <td>Angel,Shikigami</td>
  </tr>
  <tr>
  <td>Fomorian,Shikigami</td>
  </tr>
  <tr>
  <td>Hua Po,Kodama</td>
  </tr>
  <tr>
  <td>Datsue-Ba,Kodama</td>
  </tr>
  <tr>
  <td>Angel,Kodama</td>
  </tr>
  <tr>
  <td>Fomorian,Kodama</td>
  </tr>
  <tr>
  <td>Datsue-Ba,Hua Po</td>
  </tr>
  <tr>
  <td>Angel,Hua Po</td>
  </tr>
  <tr>
  <td>Fomorian,Hua Po</td>
  </tr>
  <tr>
  <td>Angel,Datsue-Ba</td>
  </tr>
  <tr>
  <td>Datsue-Ba,Fomorian</td>
  </tr>
  <tr>
  <td>Angel,Fomorian</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>It was provided by a sort of &quot;cleaner&quot; formula I made but that isn't the problem.</p>
  <p>The overall input I was testing is like this (in column A) and is also the input for the cleaner formulas for the initial pairs:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>available</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Pixie</td>
  </tr>
  <tr>
  <td>Shikigami</td>
  </tr>
  <tr>
  <td>Kodama</td>
  </tr>
  <tr>
  <td>Hua Po</td>
  </tr>
  <tr>
  <td>Datsue Ba</td>
  </tr>
  <tr>
  <td>Angel</td>
  </tr>
  <tr>
  <td>Fomorian</td>
  </tr>
  <tr>
  <td>High Pixie</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>And the expected output... is really big. Here's a sample of the first lines to get an idea (hosted in H2 of the original sheet):</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>A</th>
  <th>B</th>
  <th>C</th>
  <th>D</th>
  <th>E</th>
  <th>F</th>
  <th>G</th>
  <th>H</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Pixie</td>
  <td>Shikigami</td>
  <td>Kodama</td>
  <td>Hua Po</td>
  <td>Datsue Ba</td>
  <td>Angel</td>
  <td>Fomorian</td>
  <td>High Pixie</td>
  </tr>
  <tr>
  <td>Pixie</td>
  <td>Shikigami</td>
  <td>Kodama</td>
  <td>Hua Po</td>
  <td>Datsue Ba</td>
  <td>Fomorian</td>
  <td>Angel</td>
  <td>High Pixie</td>
  </tr>
  <tr>
  <td>Pixie</td>
  <td>Shikigami</td>
  <td>Kodama</td>
  <td>Hua Po</td>
  <td>Angel</td>
  <td>Datsue Ba</td>
  <td>Fomorian</td>
  <td>High Pixie</td>
  </tr>
  <tr>
  <td>Pixie</td>
  <td>Shikigami</td>
  <td>Kodama</td>
  <td>Hua Po</td>
  <td>Angel</td>
  <td>Fomorian</td>
  <td>Datsue Ba</td>
  <td>High Pixie</td>
  </tr>
  <tr>
  <td>Pixie</td>
  <td>Shikigami</td>
  <td>Kodama</td>
  <td>Hua Po</td>
  <td>Fomorian</td>
  <td>Datsue Ba</td>
  <td>Angel</td>
  <td>High Pixie</td>
  </tr>
  <tr>
  <td>Pixie</td>
  <td>Shikigami</td>
  <td>Kodama</td>
  <td>Hua Po</td>
  <td>Fomorian</td>
  <td>Angel</td>
  <td>Datsue Ba</td>
  <td>High Pixie</td>
  </tr>
  <tr>
  <td>Pixie</td>
  <td>Shikigami</td>
  <td>Kodama</td>
  <td>Datsue Ba</td>
  <td>Hua Po</td>
  <td>Angel</td>
  <td>Fomorian</td>
  <td>High Pixie</td>
  </tr>
  <tr>
  <td>and so on...</td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I am currently at a loss for how to fix this problem. I would like to fit at least 8 starting monsters within my sheets for analysis, if not a full 12 for the end of the game.</p>
  <p>There is probably a better, more compact way to generate these permutations than the way I have. I would probably like to boot up Excel to try this on my suped-up system and then see where it breaks offline. Yet, I want more efficient formulae to work around my &quot;array too large&quot; issues in Google Sheets. It's where I work best and where I have many other projects.</p>
  <p>PS: Shout out to Erik for his help with the full sheet and for teaching me some new techniques with LAMBDA and Named Functions. It helped with eventually solving my issue. Stack's policy restricts me from sharing the full spreadsheet for good reason (concerns about bad actors and all that). So, I made edits to this post to make it better contained. Again, sorry for the mess.</p>