Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's How to do it using depth first Recursion. Takes about 3 seconds to run on my machine. Also this will work for an arbitrary sized pairing by changing the PAIRCOUNT to say 5 if you had 5 columns instead of 4 and just .add the additional Pairs as appropriate. </p> <pre><code> void Main() { var OriginValues = new List&lt;KeyValuePair&lt;char, int&gt;&gt;(); OriginValues.Add(new KeyValuePair&lt;char, int&gt;('Q', 100)); OriginValues.Add(new KeyValuePair&lt;char, int&gt;('R', 150)); OriginValues.Add(new KeyValuePair&lt;char, int&gt;('W', 250)); OriginValues.Add(new KeyValuePair&lt;char, int&gt;('T', 30)); OriginValues.Add(new KeyValuePair&lt;char, int&gt;('Q', 90)); OriginValues.Add(new KeyValuePair&lt;char, int&gt;('R', 130)); OriginValues.Add(new KeyValuePair&lt;char, int&gt;('W', 225)); OriginValues.Add(new KeyValuePair&lt;char, int&gt;('T', 28)); OriginValues.Add(new KeyValuePair&lt;char, int&gt;('Q', 80)); OriginValues.Add(new KeyValuePair&lt;char, int&gt;('R', 110)); OriginValues.Add(new KeyValuePair&lt;char, int&gt;('W', 210)); OriginValues.Add(new KeyValuePair&lt;char, int&gt;('T', 25)); ///... and the other 7 var AllPermutation = new List&lt;List&lt;KeyValuePair&lt;char, int&gt;&gt;&gt;(); Recurse(OriginValues, ref AllPermutation); //all results will be in AllPermutation now } const int PAIRCOUNT = 4; void Recurse(List&lt;KeyValuePair&lt;char, int&gt;&gt; OriginValues, ref List&lt;List&lt;KeyValuePair&lt;char, int&gt;&gt;&gt; result, List&lt;KeyValuePair&lt;char, int&gt;&gt; itemset = null) { itemset = itemset ?? new List&lt;KeyValuePair&lt;char, int&gt;&gt;(); var temp = new List&lt;KeyValuePair&lt;char, int&gt;&gt;(itemset); if (itemset.Count == OriginValues.Count / PAIRCOUNT) { result.Add(temp); return; } for (int x = 0; x &lt; PAIRCOUNT; x++) { temp.Add(OriginValues[itemset.Count * PAIRCOUNT + x]); Recurse(OriginValues, ref result, temp); temp = new List&lt;KeyValuePair&lt;char, int&gt;&gt;(itemset); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload