Skip to content
This repository was archived by the owner on Feb 14, 2020. It is now read-only.

Commit efaeaf9

Browse files
committed
Solve day 11 part 1
1 parent 240146b commit efaeaf9

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

2018/day11.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <limits.h>
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
5+
typedef unsigned uint;
6+
7+
int main() {
8+
uint serial;
9+
scanf("%u", &serial);
10+
11+
int cells[300][300];
12+
for (uint y = 0; y < 300; ++y) {
13+
for (uint x = 0; x < 300; ++x) {
14+
uint id = (x + 1) + 10;
15+
cells[y][x] = id * (y + 1);
16+
cells[y][x] += serial;
17+
cells[y][x] *= id;
18+
cells[y][x] /= 100;
19+
cells[y][x] %= 10;
20+
cells[y][x] -= 5;
21+
}
22+
}
23+
24+
int max = INT_MIN;
25+
uint maxY = 0, maxX = 0;
26+
for (uint y = 0; y < 297; ++y) {
27+
for (uint x = 0; x < 297; ++x) {
28+
int power = cells[y][x] + cells[y][x + 1] + cells[y][x + 2]
29+
+ cells[y + 1][x] + cells[y + 1][x + 1] + cells[y + 1][x + 2]
30+
+ cells[y + 2][x] + cells[y + 2][x + 1] + cells[y + 2][x + 2];
31+
if (power < max) continue;
32+
max = power;
33+
maxY = y;
34+
maxX = x;
35+
}
36+
}
37+
printf("%u,%u\n", maxX + 1, maxY + 1);
38+
}

0 commit comments

Comments
 (0)