Compare commits
2 Commits
1ea972f4f2
...
6f080958ac
Author | SHA1 | Date | |
---|---|---|---|
6f080958ac | |||
5cb39af7b8 |
2
day04/Makefile
Normal file
2
day04/Makefile
Normal file
@ -0,0 +1,2 @@
|
||||
CFLAGS=-O2 -std=c99 -Wall -Wextra
|
||||
all: sol
|
140
day04/input
Normal file
140
day04/input
Normal file
@ -0,0 +1,140 @@
|
||||
XASXMAXXMSXXSMMSXMMSMXSMXMSSMSSSMMSMAMXMXSMMMMAXAMXSASXSSMMSSMXAMXMSAMXMMXAXXXSAMXXXXXMMXSXMXXSMASAMXMXAXXMASAMXXXMAMMMSXSXMXMMMSAASXSMSSMMS
|
||||
XASAMSSMAMMMAMAAAMASMAMAAXMASAAASAAMAMAMAAAAASMSSSSMAXAAAXASASMMMMMMXMASXMAMXXXXSMSMSXSAAXAMXMASMXMMSMSAXSXMMSXSMMAAMXAMAAMMAAAAXMXSAAAAXAAM
|
||||
MXSXMAAMXAAAXMMSSMAXMASXSSSSMMSMMSXSASMSMSSMMMAAAXXXXMMMMMXXAMMAAAASMMAAAXMASMXXXAAASAMMXSASASMMMAMXSASASASMAXXMAMSSSMSSMMAXSMMSXMMMMMMMXAMX
|
||||
SAMMMSSMMXXSXXXAAMSMSASXAAXMXXAAXXXMAXAAAXXMASMMMMMMXMXXXXSMXMSSMSASASMMXMMXMAAMASMSMSMAASXSAAAASAXAMAMXAAXMASMSSMXAMMMAMXSAMAMAASXMMSSMSAMX
|
||||
MASAAAAMSMMMMMMSMMMAMAXMMMMMXMSSMMXMSMMMMMAMXASAXAASXMMASAAXAXAXMXMXMXAASXMAMSXSAMMXMMMMMSAMXMSMSMSMMAMSMXMMASAMXAMMSASAMMXASAMSXMAMXAAXSAMA
|
||||
SSMXMSMAAMAAXXAMXASMMSMAMXSXSAMXXMAAAAXSXSAMXMASMSXMASXAMSAMXMMMSASMXMXMMAMSMXAMASXMXAASXMMMMXMMXAAXXAMXXAAMAMAMXXXASXSASXMMSAMMASXMMMMMM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ASXMMSMAMMMASAMXAASAXXXSASMMMSMSMSSXXAMXMXMASXMASMMMASXMASXMMMXSAAMAMSMAAAASMXSAMSSSMMASAAAAMMAXMAMXAXAAMAMAMXAXX
|
||||
AXXXSXMAXXMXSSSMSSMSXMSSMMSMMMXXXAMXSMXMXMMSSMSMSAMXSAMXXXXMMMMAMXXXSSXMXSAMXXMXMXAXXMASXMSMMSMMSXSAMMSXMMMSXMAXMAMXMSMXSAMSXSXSMSMMXSASMASX
|
5
day04/sample1.in
Normal file
5
day04/sample1.in
Normal file
@ -0,0 +1,5 @@
|
||||
..X...
|
||||
.SAMX.
|
||||
.A..A.
|
||||
XMAS.S
|
||||
.X....
|
10
day04/sample2.in
Normal file
10
day04/sample2.in
Normal file
@ -0,0 +1,10 @@
|
||||
MMMSXXMASM
|
||||
MSAMXMSMSA
|
||||
AMXSXMAAMM
|
||||
MSAMASMSMX
|
||||
XMASAMXAMM
|
||||
XXAMMXXAMA
|
||||
SMSMSASXSS
|
||||
SAXAMASAAA
|
||||
MAMMMXMMMM
|
||||
MXMXAXMASX
|
10
day04/sample3.in
Normal file
10
day04/sample3.in
Normal file
@ -0,0 +1,10 @@
|
||||
....XXMAS.
|
||||
.SAMXMS...
|
||||
...S..A...
|
||||
..A.A.MS.X
|
||||
XMASAMX.MM
|
||||
X.....XA.A
|
||||
S.S.S.S.SS
|
||||
.A.A.A.A.A
|
||||
..M.M.M.MM
|
||||
.X.X.XMASX
|
138
day04/sol.c
Normal file
138
day04/sol.c
Normal file
@ -0,0 +1,138 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct grid {
|
||||
char** A;
|
||||
int x, y;
|
||||
};
|
||||
|
||||
void* xrealloc(void* ptr, size_t size) {
|
||||
if (size == 0) {
|
||||
size = 1;
|
||||
}
|
||||
ptr = realloc(ptr, size);
|
||||
if (ptr == NULL) {
|
||||
fprintf(stderr, "fatal: alloc(%zd) failed", size);
|
||||
exit(1);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
int readfile(const char* filename, struct grid* out) {
|
||||
FILE *fp = fopen(filename, "r");
|
||||
if (fp == NULL) {
|
||||
perror("fopen");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int len = 0;
|
||||
int cap = 100;
|
||||
char* data = xrealloc(NULL, cap);
|
||||
for (;;) {
|
||||
if (len >= cap) {
|
||||
cap *= 2;
|
||||
data = xrealloc(data, cap);
|
||||
}
|
||||
int c = fgetc(fp);
|
||||
if (c == -1) {
|
||||
break;
|
||||
}
|
||||
data[len] = c;
|
||||
len++;
|
||||
}
|
||||
int i, nl=0;
|
||||
for (i = 0; i < len; i++) {
|
||||
if (data[i] == '\n') {
|
||||
nl++;
|
||||
}
|
||||
}
|
||||
// split on newlines
|
||||
char** lines = xrealloc(NULL, nl * sizeof(char*));
|
||||
char* p = data;
|
||||
int mincol = INT_MAX;
|
||||
i = 0;
|
||||
while (p != NULL && p < data+len) {
|
||||
lines[i++] = p;
|
||||
char* q = memchr(p, '\n', (data+len)-p);
|
||||
if (!q) {
|
||||
break; // TODO: final line?
|
||||
}
|
||||
int col = q - p;
|
||||
if (mincol > col && col > 0) {
|
||||
mincol = col;
|
||||
}
|
||||
p = q+1; // skip newline
|
||||
}
|
||||
|
||||
out->A = lines;
|
||||
out->x = mincol;
|
||||
out->y = nl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool search(struct grid *g, int x, int y, int dx, int dy, const char* word) {
|
||||
int i;
|
||||
for (i = 0; word[i] != '\0'; i++) {
|
||||
if (!(0 <= x && x < g->x && 0 <= y && y < g->y)) {
|
||||
return false;
|
||||
}
|
||||
if (g->A[y][x] != word[i]) {
|
||||
return false;
|
||||
}
|
||||
x += dx;
|
||||
y += dy;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int solve(struct grid *g) {
|
||||
int x, y;
|
||||
int count = 0;
|
||||
const char *word = "XMAS";
|
||||
for (y = 0; y < g->y; y++)
|
||||
for (x = 0; x < g->x; x++) {
|
||||
if (g->A[y][x] != 'X') continue;
|
||||
if (search(g, x, y, 0, +1, word)) { count++; }
|
||||
if (search(g, x, y, +1, 0, word)) { count++; }
|
||||
if (search(g, x, y, -1, 0, word)) { count++; }
|
||||
if (search(g, x, y, 0, -1, word)) { count++; }
|
||||
if (search(g, x, y, +1, +1, word)) { count++; }
|
||||
if (search(g, x, y, -1, -1, word)) { count++; }
|
||||
if (search(g, x, y, +1, -1, word)) { count++; }
|
||||
if (search(g, x, y, -1, +1, word)) { count++; }
|
||||
}
|
||||
printf("%d\n", count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int solve2(struct grid *g) {
|
||||
int x, y;
|
||||
int count = 0;
|
||||
const char *word = "MAS";
|
||||
for (y = 0; y < g->y; y++)
|
||||
for (x = 0; x < g->x; x++) {
|
||||
if (g->A[y][x] != 'A') continue;
|
||||
int mas = 0;
|
||||
if (search(g, x-1, y-1, +1, +1, word)) { mas++; }
|
||||
if (search(g, x+1, y+1, -1, -1, word)) { mas++; }
|
||||
if (search(g, x-1, y+1, +1, -1, word)) { mas++; }
|
||||
if (search(g, x+1, y-1, -1, +1, word)) { mas++; }
|
||||
if (mas == 2) { count++; }
|
||||
}
|
||||
printf("%d\n", count);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
struct grid g;
|
||||
readfile("sample2.in", &g);
|
||||
//readfile("input", &g);
|
||||
printf("%d %d\n", g.x, g.y);
|
||||
solve(&g);
|
||||
solve2(&g);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user