C 2024 last day part 1

This commit is contained in:
Bill Rossi 2024-12-25 01:02:03 -05:00
parent 90e02ade43
commit 9c3144c0e7

View File

@ -0,0 +1,70 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "../../lib/aoc.h"
int main() {
char *line;
int locks[2000][5];
int locks_count = 0;
int keys[2000][5];
int keys_count = 0;
int pins[5];
do {
line = aoc_read_line();
if (line == NULL) break;
for (int j = 0; j < 5; j++) {
pins[j] = 0;
}
if (line[0] == '.') {
for (int i = 0; i < 6; i++) {
line = aoc_read_line();
for (int j = 0; j < 5; j++) {
if (pins[j] == 0 && line[j] == '#') pins[j] = 5 - i;
}
}
for (int j = 0; j < 5; j++) {
keys[keys_count][j] = pins[j];
}
keys_count++;
} else if(line[0] == '#') {
for (int i = 0; i < 6; i++) {
line = aoc_read_line();
for (int j = 0; j < 5; j++) {
if (line[j] == '#') pins[j] = i + 1;
}
}
for (int j = 0; j < 5; j++) {
locks[locks_count][j] = pins[j];
}
locks_count++;
}
line = aoc_read_line();
if (line == NULL) break;
} while (line != NULL);
int pairs = 0;
for (int i = 0; i < locks_count; i++) {
for (int j = 0; j < keys_count; j++) {
for (int k = 0; k < 5; k++) {
if (locks[i][k] + keys[j][k] >= 6) goto bad;
}
pairs++;
bad:
}
}
printf("Part 1: %d", pairs);
aoc_free();
exit(0);
}