From b2723a0c5f75b3cc23db71c0e63836e828355639 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Mon, 15 Dec 2025 19:06:17 +0200 Subject: [PATCH] aoc2025: Implement day12 solution --- userspace/aoc2025/CMakeLists.txt | 1 + userspace/aoc2025/day12/CMakeLists.txt | 9 +++ userspace/aoc2025/day12/main.cpp | 80 ++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 userspace/aoc2025/day12/CMakeLists.txt create mode 100644 userspace/aoc2025/day12/main.cpp diff --git a/userspace/aoc2025/CMakeLists.txt b/userspace/aoc2025/CMakeLists.txt index d96012b4..cf7a15f0 100644 --- a/userspace/aoc2025/CMakeLists.txt +++ b/userspace/aoc2025/CMakeLists.txt @@ -10,6 +10,7 @@ set(AOC2025_PROJECTS day9 day10 day11 + day12 full ) diff --git a/userspace/aoc2025/day12/CMakeLists.txt b/userspace/aoc2025/day12/CMakeLists.txt new file mode 100644 index 00000000..e092c852 --- /dev/null +++ b/userspace/aoc2025/day12/CMakeLists.txt @@ -0,0 +1,9 @@ +set(SOURCES + main.cpp +) + +add_executable(aoc2025_day12 ${SOURCES}) +banan_include_headers(aoc2025_day12 ban) +banan_link_library(aoc2025_day12 libc) + +install(TARGETS aoc2025_day12 OPTIONAL) diff --git a/userspace/aoc2025/day12/main.cpp b/userspace/aoc2025/day12/main.cpp new file mode 100644 index 00000000..70a3b2d9 --- /dev/null +++ b/userspace/aoc2025/day12/main.cpp @@ -0,0 +1,80 @@ +#include +#include + +using i8 = int8_t; +using i16 = int16_t; +using i32 = int32_t; +using i64 = int64_t; + +using u8 = uint8_t; +using u16 = uint16_t; +using u32 = uint32_t; +using u64 = uint64_t; + +// ehh im not happy about this but all inputs were crafted such that there +// is no need to overlap any presents, so a simple 3x3 fitting check works + +i64 part1(FILE* fp) +{ + char chs[2] {}; + chs[0] = fgetc(fp); + chs[1] = fgetc(fp); + + char ch; + while ((ch = fgetc(fp)) != 'x') + { + chs[0] = chs[1]; + chs[1] = ch; + } + + ungetc(ch, fp); + ungetc(chs[0], fp); + ungetc(chs[1], fp); + + i64 result = 0; + + u32 w, h; + while (fscanf(fp, "%" SCNu32 "x%" SCNu32 ":", &w, &h) == 2) + { + u32 blocks = 0; + + u32 count; + while (fscanf(fp, "%" SCNu32 "%c", &count, &ch) == 2 && ch != '\n') + blocks += count; + blocks += count; + + if ((w / 3) * (h / 3) >= blocks) + result++; + } + + return result; +} + +i64 part2(FILE* fp) +{ + (void)fp; + return -1; +} + +int main(int argc, char** argv) +{ + const char* file_path = "/usr/share/aoc2025/day12_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); +}