-
Notifications
You must be signed in to change notification settings - Fork 0
/
day 11
51 lines (47 loc) · 1.44 KB
/
day 11
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
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
int main()
{
// always a 20x20 matrix
const unsigned int Size = 20;
unsigned int matrix[Size][Size];
// read from console
for (unsigned int y = 0; y < Size; y++)
for (unsigned int x = 0; x < Size; x++)
std::cin >> matrix[x][y];
unsigned int best = 0;
// walk through all cells of the matrix
for (unsigned int y = 0; y < Size; y++)
for (unsigned int x = 0; x < Size; x++)
{
// three more horizontal cells (right)
if (x + 3 < Size)
{
unsigned int current = matrix[x][y] * matrix[x+1][y] * matrix[x+2][y] * matrix[x+3][y];
if (best < current)
best = current;
}
// three more vertical cells available (down)
if (y + 3 < Size)
{
unsigned int current = matrix[x][y] * matrix[x][y+1] * matrix[x][y+2] * matrix[x][y+3];
if (best < current)
best = current;
}
// three more diagonal cells (right-down)
if (x + 3 < Size && y + 3 < Size)
{
unsigned int current = matrix[x][y] * matrix[x+1][y+1] * matrix[x+2][y+2] * matrix[x+3][y+3];
if (best < current)
best = current;
}
// three more diagonal cells (left-down)
if (x + 3 < Size && y >= 3)
{
unsigned int current = matrix[x][y] * matrix[x+1][y-1] * matrix[x+2][y-2] * matrix[x+3][y-3];
if (best < current)
best = current;
}
}
std::cout << best << std::endl;
return 0;
}