-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0011.cpp
More file actions
52 lines (48 loc) · 1.24 KB
/
0011.cpp
File metadata and controls
52 lines (48 loc) · 1.24 KB
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
52
#include <iostream>
#include <fstream>
#include <array>
#include <functional>
#include <vector>
void fn0() {
std::array<int, 20*20> grid;
std::fstream in("0011.txt");
int i = 0;
while (!in.eof() && i < 20*20) {
in >> grid[i++];
}
int max = 0;
for (int x = 0; x < 20; x++) {
for (int y = 0; y < 20; y++) {
// left
if (x < 20 - 3) {
int p = grid[y*20 + x] * grid[y*20 + x + 1] * grid[y*20 + x + 2] * grid[y*20 + x + 3];
if (p > max) {
max = p;
}
}
// down
if (y < 20 - 3) {
int p = grid[y*20 + x] * grid[(y+1)*20 + x] * grid[(y+2)*20 + x] * grid[(y+3)*20 + x];
if (p > max) {
max = p;
}
}
// diag down left
if (x < 20 - 3 && y < 20 - 3) {
int p = grid[y*20 + x] * grid[(y+1)*20 + x + 1] * grid[(y+2)*20 + x + 2] * grid[(y+3)*20 + x + 3];
if (p > max) {
max = p;
}
}
// diag up left
if (x < 20 - 3 && y > 2) {
int p = grid[y*20 + x] * grid[(y-1)*20 + x + 1] * grid[(y-2)*20 + x + 2] * grid[(y-3)*20 + x + 3];
if (p > max) {
max = p;
}
}
}
}
std::cout << max << std::endl;
}
std::vector<std::function<void()>> progs = { fn0 };