コード例 #1
0
    private static bool RowPatternsMatch(string[] rows, int index1, int index2)
    {
        DotRow row1             = RowPattern(rows[index1]);
        DotRow row2             = RowPattern(rows[index2]);
        bool   rowPatternsMatch = true;

        if (row1.Count() != row2.Count())
        {
            return(false);
        }

        for (int i = 0; i < row1.Count(); i++)
        {
            if (row1[i].simbol != row2[i].simbol)
            {
                return(false);
            }
        }

        for (int i = 0; i < row1.Count(); i++)
        {
            if (Math.Abs(row1[i].count - row2[i].count) > 2)
            {
                return(false);
            }
        }

        return(rowPatternsMatch);
    }
コード例 #2
0
    private static DotRow RowPattern(string row)
    {
        DotRow rowPattern = new DotRow();

        rowPattern.Add(new Dot(row[0], 1));

        for (int i = 1; i < row.Length; i++)
        {
            if (row[i] == row[i - 1])
            {
                // increase the count if the simbol is the same
                Dot tmp = rowPattern[rowPattern.Count() - 1];
                tmp.count++;
                rowPattern[rowPattern.Count() - 1] = tmp;
            }
            else
            {
                Dot newPattern = new Dot(row[i], 1);
                rowPattern.Add(newPattern);
            }
        }

        return(rowPattern);
    }