-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyVerifier.cs
40 lines (33 loc) · 1.1 KB
/
MyVerifier.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System.Collections.Generic;
using System.Linq;
namespace Façade
{
public class MyVerifier
{
public static bool Verify(List<List<int>> array)
{
if (!array.Any()) return false;
var rowCount = array.Count;
var colCount = array[0].Count;
var expected = array.First().Sum();
for (var row = 0; row < rowCount; ++row)
if (array[row].Sum() != expected)
return false;
for (var col = 0; col < colCount; ++col)
if (array.Select(a => a[col]).Sum() != expected)
return false;
var diag1 = new List<int>();
var diag2 = new List<int>();
for (var r = 0; r < rowCount; ++r)
for (var c = 0; c < colCount; ++c)
{
if (r == c)
diag1.Add(array[r][c]);
var r2 = rowCount - r - 1;
if (r2 == c)
diag2.Add(array[r][c]);
}
return diag1.Sum() == expected && diag2.Sum() == expected;
}
}
}