aoc2024: Implement day25 solution

This was a nice AOC season. First time I fully completed it! I may still
optimize my solutions as some of them are a bit slow...
This commit is contained in:
Bananymous 2024-12-25 18:13:57 +02:00
parent 3607e2e759
commit 55c8a15983
3 changed files with 90 additions and 0 deletions

View File

@ -23,6 +23,7 @@ set(AOC2024_PROJECTS
day22
day23
day24
day25
full
)

View File

@ -0,0 +1,9 @@
set(SOURCES
main.cpp
)
add_executable(aoc2024_day25 ${SOURCES})
banan_include_headers(aoc2024_day25 ban)
banan_link_library(aoc2024_day25 libc)
install(TARGETS aoc2024_day25 OPTIONAL)

View File

@ -0,0 +1,80 @@
#include <BAN/Array.h>
#include <BAN/Vector.h>
#include <inttypes.h>
#include <stdio.h>
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
using isize = ssize_t;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using usize = size_t;
i64 part1(FILE* fp)
{
BAN::Vector<BAN::Array<u8, 5>> locks;
BAN::Vector<BAN::Array<u8, 5>> keys;
for (;;)
{
char buffer[6*7 + 1];
if (fread(buffer, 1, sizeof(buffer), fp) < sizeof(buffer) - 1)
break;
BAN::Array<u8, 5> obj;
for (usize j = 1; j <= 5; j++)
for (usize i = 0; i < 5; i++)
obj[i] += (buffer[6 * j + i] == '#');
MUST((buffer[0] == '#' ? locks : keys).push_back(obj));
}
u32 result = 0;
for (auto lock : locks)
{
for (auto key : keys)
{
bool valid = true;
for (usize i = 0; i < 5 && valid; i++)
valid = (key[i] + lock[i] <= 5);
result += valid;
}
}
return result;
}
i64 part2(FILE* fp)
{
(void)fp;
return -1;
}
int main(int argc, char** argv)
{
const char* file_path = "/usr/share/aoc2024/day25_input.txt";
if (argc >= 2)
file_path = argv[1];
FILE* fp = fopen(file_path, "r");
if (fp == nullptr)
{
perror("fopen");
return 1;
}
printf("part1: %" PRId64 "\n", part1(fp));
fseek(fp, 0, SEEK_SET);
printf("part2: %" PRId64 "\n", part2(fp));
fclose(fp);
}