title: Grouping numbers based on occurrences?
body: <p>Given the following three sequences of numbers, I would like to figure out how to group the numbers to find the closest relations between them.</p>
  
  <pre><code>1,2,3,4
  4,3,5
  2,1,3
  ...
  </code></pre>
  
  <p>I'm not sure what the algorithm(s) I'm looking for are called, but we can see stronger relations with some of the numbers than with others.</p>
  
  <p>These numbers appear together twice:</p>
  
  <pre><code>1 &amp; 2
  1 &amp; 3
  2 &amp; 3
  3 &amp; 4
  </code></pre>
  
  <p>Together once:</p>
  
  <pre><code>1 &amp; 4
  2 &amp; 4
  3 &amp; 5
  4 &amp; 5
  </code></pre>
  
  <p>So for example, we can see there must be a relationship between <code>1, 2, &amp; 3</code> since they all appear together at least twice. You could also say that <code>3 &amp; 4</code> are closely related since they also appear twice. However, the algorithm might pick <code>[1,2,3]</code> (over <code>[3,4]</code>) since it's a bigger grouping (more inclusive). </p>
  
  <p>We can form any of the following groupings if we stick the numbers used most often together in a group:</p>
  
  <pre><code>[1,2,3] &amp; [4,5]
  [1,2]   &amp; [3,4]   &amp; [5]
  [1,2]   &amp; [3,4,5]
  [1,2]   &amp; [3,4]   &amp; [5]
  </code></pre>
  
  <p>If duplicates are allowed, you could even end up with the following groups:</p>
  
  <pre><code>[1,2,3,4] [1,2,3] [3,4] [5]
  </code></pre>
  
  <p>I can't say which grouping is most "correct", but all four of these combos all find different ways of semi-correctly grouping the numbers. I'm not looking for a specific grouping - just a general cluster algorithm that works fairly well and is easy to understand.</p>
  
  <p>I'm sure there are many other ways to use the occurrence count to group them as well. What would be a good base grouping algorithm for these? Samples in Go, Javascript, or PHP are preferred. </p>