title: Ruby search for the same values in multidimensional array
body: <p>I have an array with many arrays inside (2d) (in this example there are four of them):</p>
  
  <pre><code>[
  [13, 15, 18, 23, 23, 11, 14, 19, 19, 5, 10, 10, 8, 8], 
  [8, 15, 19, 21, 21, 12, 16, 18, 18, 11, 13, 13, 6, 6], 
  [9, 15, 21, 23, 23, 7, 13, 15, 15, 12, 14, 14, 8, 8], 
  [2, 8, 14, 16, 16, 7, 13, 15, 15, 12, 14, 14, 8, 8]
  ]
  </code></pre>
  
  <p>I need to find if any element on any of these arrays is the same and at the same index as in other array. I need to get all those numbers and their indexes. </p>
  
  <p>For ex. <strong>First_array[1] = 15</strong>, as well as <strong>second_array[1] = 15</strong> and <strong>third_array[1] = 15</strong>. So I need these, with their indexes. </p>
  
  <p>Also all needed values must come from arrays that are to the left or to the right to the array. For ex. - <strong>array_one[3] = 23</strong>, <strong>array_two[3] = 21</strong> and <strong>array_three[3] = 23</strong>. I dont need these since array_two has a different value and it separates <strong>array_one</strong> from <strong>array_three</strong>.</p>
  
  <p>And What I can get is the length of arrays (they all the same length) and the number of arrays, as variables.</p>
  
  <p>I hope you got my point :) </p>
  
  <hr>
  
  <p>Looks like I am abit closer to my goal. It seems this checks well for the second array (so only two first arrays being checked, but if this was done, the rest should be much easier). And do not judge me, judge just the code :D I know its ugly, its just a prototype:</p>
  
  <pre><code>array.each do |c|
     c.each do |v|
      c.each_with_index do |k, i|
        next_array = array[i + 1]
            if next_array.include? v 
              its_index = next_array.index(v) 
              if c.index(v) == its_index
              p v
            end
            end
          break
      end
     end 
     return
  end
  </code></pre>