using System;
using System.Collections.Generic;
namespace matrix
{
internal class Program
{
private static void Main(string[] args)
{
if (args.Length > 0)
return;
string[] matrix =
{
"1b2ba",
"b====",
"ccb++",
"ccab+"
};
HorizontalLeftToRight(matrix);
VerticalTopToBottom(matrix);
DiagonalUp(matrix);
DiagonalDown(matrix);
Console.ReadLine();
}
private static void HorizontalLeftToRight(IReadOnlyList<string> matrix)
{
for (var row = 0; row < matrix.Count; row++)
{
var count = 0;
for (var col = 0; col < matrix[0].Length; col++)
{
count++;
try
{
if (matrix[row][col].Equals(matrix[row][col + 1])) continue;
if (count > 1)
Console.WriteLine("{0} [{1}, {2}] \'{3}\' {4}", Convert.ToChar(26), row, col - count + 1, matrix[row][col], count);
}
catch (IndexOutOfRangeException)
{
if (count > 1)
Console.WriteLine("{0} [{1}, {2}] \'{3}\' {4}", Convert.ToChar(26), row, col - count + 1, matrix[row][col], count);
}
count = 0;
}
}
}
private static void VerticalTopToBottom(IReadOnlyList<string> matrix)
{
for (var col = 0; col < matrix[0].Length; col++)
{
var count = 0;
for (var row = 0; row < matrix.Count; row++)
{
count++;
try
{
if (matrix[row][col].Equals(matrix[row + 1][col])) continue;
if (count > 1)
Console.WriteLine("{0} [{1}, {2}] \'{3}\' {4}", Convert.ToChar(25), row - count + 1, col, matrix[row][col], count);
}
catch (ArgumentOutOfRangeException)
{
if (count > 1)
Console.WriteLine("{0} [{1}, {2}] \'{3}\' {4}", Convert.ToChar(25), row - count + 1, col, matrix[row][col], count);
}
count = 0;
}
}
}
private static void DiagonalUp(IReadOnlyList<string> matrix)
{
for (var row = 1; row < matrix.Count; row++)
{
var r = row;
var count = 0;
for (var col = 0; col < matrix[0].Length; col++)
{
count++;
try
{
if (matrix[r][col].Equals(matrix[r - 1][col + 1])) continue;
if (count > 1)
Console.WriteLine("{0} [{1}, {2}] \'{3}\' {4}", Convert.ToChar(47), r + count - 1, col - count + 1, matrix[r][col], count);
}
catch (IndexOutOfRangeException)
{
if (count > 1)
Console.WriteLine("{0} [{1}, {2}] \'{3}\' {4}", Convert.ToChar(47), r + count - 1, col - count + 1, matrix[r][col], count);
}
catch (ArgumentOutOfRangeException)
{
if (count > 1)
Console.WriteLine("{0} [{1}, {2}] \'{3}\' {4}", Convert.ToChar(47), r + count - 1, col - count + 1, matrix[r][col], count);
}
finally
{
r--;
}
count = 0;
}
}
for (var col = 1; col < matrix[0].Length; col++)
{
var c = col;
var count = 0;
for (var row = matrix.Count - 1; row > -1; row--)
{
count++;
try
{
if (matrix[row][c].Equals(matrix[row - 1][c + 1])) continue;
if (count > 1)
Console.WriteLine("{0} [{1}, {2}] \'{3}\' {4}", Convert.ToChar(47), row + count - 1, c - count + 1, matrix[row][c], count);
}
catch (IndexOutOfRangeException)
{
if (count > 1)
Console.WriteLine("{0} [{1}, {2}] \'{3}\' {4}", Convert.ToChar(47), row + count - 1, c - count + 1, matrix[row][c], count);
}
catch (ArgumentOutOfRangeException)
{
if (count > 1)
Console.WriteLine("{0} [{1}, {2}] \'{3}\' {4}", Convert.ToChar(47), row + count - 1, c - count + 1, matrix[row][c], count);
}
finally
{
c++;
}
count = 0;
}
}
}
private static void DiagonalDown(IReadOnlyList<string> matrix)
{
for (var col = matrix[0].Length - 2; col > -1; col--)
{
var c = col;
var count = 0;
for (var row = 0; row < matrix.Count; row++)
{
count++;
try
{
if (matrix[row][c].Equals(matrix[row + 1][c + 1])) continue;
if (count > 1)
Console.WriteLine("{0} [{1}, {2}] \'{3}\' {4}", Convert.ToChar(92), row - count + 1, c - count + 1, matrix[row][c], count);
}
catch (IndexOutOfRangeException)
{
if (count > 1)
Console.WriteLine("{0} [{1}, {2}] \'{3}\' {4}", Convert.ToChar(92), row - count + 1, c - count + 1, matrix[row][c], count);
}
catch (ArgumentOutOfRangeException)
{
if (count > 1)
Console.WriteLine("{0} [{1}, {2}] \'{3}\' {4}", Convert.ToChar(92), row - count + 1, c - count + 1, matrix[row][c], count);
}
finally
{
c++;
}
count = 0;
}
}
for (var row = 1; row < matrix.Count; row++)
{
var r = row;
var count = 0;
for (var col = 0; col < matrix[0].Length; col++)
{
count++;
try
{
if (matrix[r][col].Equals(matrix[r + 1][col + 1])) continue;
if (count > 1)
Console.WriteLine("{0} [{1}, {2}] \'{3}\' {4}", Convert.ToChar(92), r - count + 1, col - count + 1, matrix[r][col], count);
}
catch (IndexOutOfRangeException)
{
if (count > 1)
Console.WriteLine("{0} [{1}, {2}] \'{3}\' {4}", Convert.ToChar(92), r - count + 1, col - count + 1, matrix[r][col], count);
}
catch (ArgumentOutOfRangeException)
{
if (count > 1)
Console.WriteLine("{0} [{1}, {2}] \'{3}\' {4}", Convert.ToChar(92), r - count + 1, col - count + 1, matrix[r][col], count);
}
finally
{
r++;
}
count = 0;
}
}
}
}
}