title: How can I find, and store, the groups of values in a two-dimensional array?
body: <p>I'm working with a two dimensional array that contains values at each spot, and I need to find a way to calculate and return the number of groups made of values adjacent to the same value. For example:</p>
  
  <pre><code>+ - -
  + - -
  + + +
  </code></pre>
  
  <p>In this ASCII version of a 3x3 array, there would be groups of two values, '+', and '-'.  I would define this array to have two distinct groups, based on adjacency. If two squares are not connected by path of adjacancy, they would not be in the same group.</p>
  
  <p>3 groups:</p>
  
  <pre><code>+ - -
  - - -
  + - -
  </code></pre>
  
  <p>5 groups :</p>
  
  <pre><code>+ - +
  - - -
  + - +
  </code></pre>
  
  <p>How can I write an algorithm that could find the number of groups, their values and positions? </p>
  
  <p>Thanks for the help!</p>