def num_matching(one_bigrams, two_bigrams, acc = 0)
      return acc if one_bigrams.empty? || two_bigrams.empty?

      one_two = one_bigrams.index(two_bigrams[0])
      two_one = two_bigrams.index(one_bigrams[0])

      if one_two.nil? && two_one.nil?
        num_matching(one_bigrams.drop(1), two_bigrams.drop(1), acc)
      else
        # If one is nil, it is set to the other
        two_one ||= one_two
        one_two ||= two_one

        if one_two < two_one
          num_matching(one_bigrams.drop(one_two + 1),
                       two_bigrams.drop(1), acc + 1)
        else
          num_matching(one_bigrams.drop(1),
                       two_bigrams.drop(two_one + 1), acc + 1)
        end
      end
    end
def num_matching(one_bigrams, two_bigrams, acc = 0)
      return acc if one_bigrams.empty? || two_bigrams.empty?

      one_two = one_bigrams.index(two_bigrams[0])
      two_one = two_bigrams.index(one_bigrams[0])

      if one_two.nil? && two_one.nil?
        num_matching(one_bigrams.drop(1), two_bigrams.drop(1), acc)
      else
        # If one is nil, it is set to the other
        two_one ||= one_two
        one_two ||= two_one

        if one_two < two_one
          num_matching(one_bigrams.drop(one_two + 1),
                       two_bigrams.drop(1), acc + 1)
        else
          num_matching(one_bigrams.drop(1),
                       two_bigrams.drop(two_one + 1), acc + 1)
        end
      end
    end
def num_matching ( one_bigrams , two_bigrams , acc = 0 ) return acc if one_bigrams . empty? || two_bigrams . empty? one_two = one_bigrams . index ( two_bigrams [ 0 ] ) two_one = two_bigrams . index ( one_bigrams [ 0 ] ) if one_two . nil? && two_one . nil? num_matching ( one_bigrams . drop ( 1 ) , two_bigrams . drop ( 1 ) , acc ) else # If one is nil, it is set to the other two_one ||= one_two one_two ||= two_one if one_two < two_one num_matching ( one_bigrams . drop ( one_two + 1 ) , two_bigrams . drop ( 1 ) , acc + 1 ) else num_matching ( one_bigrams . drop ( 1 ) , two_bigrams . drop ( two_one + 1 ) , acc + 1 ) end end end
Returns the number of matching bigrams between the two sets of bigrams
Returns the number of matching bigrams between the two sets of bigrams