From 9282b3d5311ba5b937c3c80b3e5736a948e437f4 Mon Sep 17 00:00:00 2001 From: Grant Horner Date: Thu, 4 Dec 2025 17:41:43 -0500 Subject: [PATCH] finish day 4 --- CMakeLists.txt | 1 + day4.cpp | 152 +++++++++++++++++++++++++++++++++++++++++++++++++ day4input.txt | 140 +++++++++++++++++++++++++++++++++++++++++++++ run_tests.cpp | 1 + utils.h | 19 +++++++ 5 files changed, 313 insertions(+) create mode 100644 day4.cpp create mode 100644 day4input.txt create mode 100644 utils.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4be6d78..e4f145a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,4 +8,5 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS true) add_executable(cpp_tests doctest.h run_tests.cpp + utils.h ) diff --git a/day4.cpp b/day4.cpp new file mode 100644 index 0000000..15edfd5 --- /dev/null +++ b/day4.cpp @@ -0,0 +1,152 @@ +// +// Created by Grant Horner on 12/4/25. +// + +#include +#include +#include + +#include "doctest.h" +#include "utils.h" + +namespace day4 { +const std::string sample = + "..@@.@@@@.\n" + "@@@.@.@.@@\n" + "@@@@@.@.@@\n" + "@.@@@@..@.\n" + "@@.@@@@.@@\n" + ".@@@@@@@.@\n" + ".@.@.@.@@@\n" + "@.@@@.@@@@\n" + ".@@@@@@@@.\n" + "@.@.@@@.@.\n"; + +enum class Point : char { + Paper = '@', + Empty = '.', +}; + +template +std::array get_surrounding(const std::vector &lines, size_t x, size_t y) noexcept { + std::array points = {}; + size_t i = 0; + for (int dy = -1; dy < 2; ++dy) { + if (y + dy < 0 || y + dy >= lines.size()) { continue; } + for (int dx = -1; dx < 2; ++dx) { + if (x + dx < 0 || x + dx >= lines[0].size()) { continue; } + if (dx == 0 && dy == 0) continue; + + points[i] = lines[y + dy][x + dx]; + i++; + } + } + + return points; +} + +uint32_t solve_first(const std::string_view input) noexcept { + const auto lines = std::string_view{input} + | std::views::split('\n') + | std::views::transform(to_string_view) + | std::views::filter([](const auto s) { return !s.empty(); }) + | std::ranges::to(); + + uint32_t accessible = 0; + + for (size_t y = 0; y < lines.size(); ++y) { + for (size_t x = 0; x < lines[0].size(); ++x) { + const auto c = lines[y][x]; + if (c != '@') continue; + size_t num_paper = 0; + for (const char p: get_surrounding(lines, x, y)) { + if (p == '@') { + num_paper++; + } + if (num_paper == 4) { + break; + } + } + + if (num_paper < 4) { + accessible++; + } + } + } + + return accessible; +} + +template +std::vector > remove_paper(const std::vector &lines) { + std::vector > removable = {}; + + for (size_t y = 0; y < lines.size(); ++y) { + for (size_t x = 0; x < lines[0].size(); ++x) { + const auto c = lines[y][x]; + if (c != '@') continue; + size_t num_paper = 0; + for (const char p: get_surrounding(lines, x, y)) { + if (p == '@') { + num_paper++; + } + if (num_paper == 4) { + break; + } + } + + if (num_paper < 4) { + removable.emplace_back(x, y); + } + } + } + + return removable; +} + +uint32_t solve_second(const std::string_view input) { + std::vector lines = std::string_view{input} + | std::views::split('\n') + | std::views::transform([](const auto r) { + return std::string(r.data(), r.size()); + }) + | std::views::filter([](const auto &s) { return !s.empty(); }) + | std::ranges::to(); + bool removed = false; + uint32_t total_removed = 0; + do { + removed = false; + const auto removable = remove_paper(lines); + if (!removable.empty()) { + removed = true; + } + for (auto [x, y]: removable) { + lines[y][x] = '.'; + total_removed++; + } + } while (removed); + + return total_removed; +} + +TEST_SUITE_BEGIN("Day 4"); + +TEST_CASE("solves first sample") { + CHECK(solve_first(sample) == 13); +} + +TEST_CASE("solves first puzzle") { + CHECK(solve_first(read_file("day4input.txt")) == 1626); +} + + +TEST_CASE("solves second sample") { + CHECK(solve_second(sample) == 43); +} + +TEST_CASE("solves second puzzle") { + CHECK(solve_second(read_file("day4input.txt")) == 9173); +} + +TEST_SUITE_END(); +} diff --git a/day4input.txt b/day4input.txt new file mode 100644 index 0000000..8873b54 --- /dev/null +++ b/day4input.txt @@ -0,0 +1,140 @@ +@.@.@@@@@@@@.@.@@@@@@@@@@@@@.@@@@..@@@@.@@...@@@@.@@...@@@@.@@@.@@@@@@..@.@.@@@@.@..@@..@@.@.....@@@@..@@@@@@@@@@@.@@.@.@@@@.@..@@@@..@@@.@. +.@.@@.@@@..@@@.@@..@@@@@.@.@@@@@.@@.@@.@@..@...@@@@@@@...@@..@..@@@@@@.@@@@..@..@@@@@.@.@.@.@@@@.@.@.@.@@@@@@@@...@@..@.@.@@@@@...@@..@@@@@. +.@@.@@@.@.@.@@.@@@@@@@@@@..@..@@..@@..@.@@..@@.@@.@.@@.@..@@@@@.@@@@@@@..@@@.@.@..@.@@@@@@@..@@..@@.@.@.@@.....@@@..@@.@..@@.@...@@@..@.@@@@ +....@@@@@@..@@@..@@@@@.@.@.@.@@@@@@..@.@@@.@....@.@@@@@.@@.@@@@@@.@@@@@@.@@..@@@@...@@@@@@@@@@..@@.@@.@...@.@.@@@@.@.@@@@.@.@@.@@.@..@.@...@ +@@.@@.@..@@@......@@.@.@@.@@.@.@..@..@@@..@..@@@@@@..@@.@@@@@@@.@.@@@..@.@.@.@.@@@@.@@...@.@@@..@@@@..@@@@@@@@@@@.@@.@@@@@@@.@@@@@..@..@..@@ +@@@@@@@.@.@.@@@@@.@@@@@@@@@.@@@@@@..@@@@@@...@.@..@.@.@@@@@@@..@.@@@@@@@.@@@@@.@@@.@...@@.@..@@@@.@@@@@@..@@@@@.@@@.@....@@..@.@.@@@@@@@...@ +@@.@@@@.@.@@@.@@@..@@@@@.@@@@@@@@@@.@@@@.@.@@@@@@@.@....@@@.@.@@@@.@....@@..@@@@@..@@@@..@@....@@@@.@@@..@@@@@@.@..@@.@@@@.@@@@..@@@@.@@@..@ +..@@..@@@.@@..@@.@@@.@..@@@.@.@@@..@@@@@@.@.@@@@.@.@@..@@..@.@.@@@@........@@@@.@@@.@@.@@@@@.@@@.@@..@.@@.@.@@@.@@@@@.@@@.@..@@@@..@.@@.@@.@ +@@.@@...@..@@@@@.@@@@.@@@.@@..@.@...@@..@@@@@..@.@@@@@@@..@@@@.@@@@@.@.@@@.@@@....@.@@@.@.@.......@@.@@@..@..@@@@@@@...@..@@.@@@@@.@@@@@..@. +...@@@@.@...@@.@.@..@@.@@@..@@.@@@..@...@@@.@..@@@@@..@@.@@..@@...@@.@..@@.@@@@@@@@.@.@.@@@@@@@@@.@...@..@@@@..@@.@..@.@@@@@@..@@.@@@@..@..@ +@.@.@@@@.@.@.@.@@..@.@@@.@@@...@.@.@.@@.@@@@@@......@@.@@.@@@@@.@@.@@@@....@...@@@@.@@@@...@.@@.@.@@@@.@@@@.@....@@@.@@@@@@@@@@.@@@@.@@@@@.. +@.@@@@@.@.@..@@..@...@@@.@..@.@@@@@@.@@@@@.@@.@.@.@@...@@@.@@.@.@@@...@.@.@..@.@@..@@...@@@.@.@..@@@@.@@@@..@@@@@.@.@..@..@.@.@@.@....@....@ +@@@@@@@@@.@.@.....@@....@@@.@@.@@@@@.@@.@.@@@@@..@..@@.@...@.@.@@@.@.@@@@@@..@@.@@....@..@@.@.@@@@.@@.@..@.@@@@.@@.@@@..@@.@@...@@..@@.@@.@. +.@@@..@..@@.@@@.@@@@.@@@.@..@@.@@@..@@@@.@@@@.@.@@@@@@@@@.@.@@@@.@@@.....@@@@@.@@@@@@@@@@@..@@..@.@@@@...@@@@.@@@@@@@...@@@@@@@@@@@.@@@....@ +@@@@@..@@..@@.@@@@.@.@@@@@.@@.@@.@..@...@@@.@@.@@@@@@.@.@@@..@@@@@@@@@@.@@.@..@.@@@..@.@.@.@...@@@@@..@@@.@@@.@@@....@@.@.@..@@.@@.@@.@@..@. +@@@@@@@@.@@@@.@@@..@..@.@@..@@.@..@@@.@.@@...@@@@@.@@@..@@@@@@@@..@@@@...@.@..@.@@@@@@..@.@....@..@@@@.@@@@@@.@@@....@@.@@@@.@@@@@..@@.@..@. +@@@@.@@@.@@..@..@@@..@@@@@@@@@@@..@.@@@..@@@@..@@@@@@@@@@@@@@..@@@..@@@@@@@@@.@..@...@@@.@@.@.@......@@.@..@@@.@...@.@.@@@.@@@@...@@.@.@..@@ +@@.@.@@@@@@@@.@@@..@.....@..@.@@.@@@@....@@@...@@@@@@@@@....@.@@@@..@@.@@@@@.@.@@.@@.@.@@@@@@@@@@@.@.@.@@.@@@@..@.@.@.@@@.@@@.@@.@@...@.@@@. +@..@@.@@.@@@..@@.@@@@@@.@.@@.@.@.....@..@..@@.@@.@@@@@@@@..@@.@@@@@@@.@@@@...@@@.@@..@@..@..@@@.@.....@.@@.@@@@@...@@.@@@.@@@.@@@.@@..@.@.@@ +@@@@.@@@@@.@.@@.@...@.@@.@@@@@@@@@.@@@@@@.@@..@@@.@@@..@@.@.@@.@@@@@@.@@@.@..@@.@@.@@..@.@.@@@.@@@@@.@@.@...@@@.@@.@@@@@.@@..@@@@..@.@@@.@@@ +.@@@@.@....@..@@@@@@.@@@.@@@.@@@@@.@..@@@@@...@@@@.@@.@@@@@@@@.@@@@.@@@.@@..@...@@..@@.@...@@@.@@@@@@...@.@@@@@@@@@..@@.@@@.@@@.@.@@@.@..@@@ +@@@..@@@@.@@..@@@@..@@@.@..@....@@.@..@@.@..@@@@....@@.@.@.@.@@.@@@@@@@..@@@.@@@@..@@...@@.@@@.@@@@@....@@@@.@@..@@@.@@.@@..@@.@@.@...@@@..@ +@@@@@.@@@...@.@@..@.@@.@@..@..@.@.@@..@.....@@@@..@.@@@@.@@.@@@@@@@@@.@@..@@@@@@..@@..@..@.@@@@@@..@..@....@@@@@.@@@@@@..@@@@@@@@.@@..@@.@.. +.@...@@@@@@.@@@.@@@.@@@.@.@@@.@@@@@@@....@@@@@@.@..@@@.@@@@.@@@.@..@@@@.@@@..@.@.@@@@..@.@.@@...@@@.@.@@@.@.@@@@@@@.@@..@@.@.@.@.@.@@@@.@@@@ +@@@.@@.@@@@@@.@@@@@..@@@.@.@..@.@@@@.@.....@@@.@......@@@.@...@@@..@@@..@@.@...@.@@@@.@.@@.@@@@@@@@.@@.@@@.@.@...@@@@..@.@.@.@@@..@@@@@@.@@@ +@..@@.@@@@@@@@@@.@@..@.@.@@@@...@@..@..@@.@@@@.@.@....@.@@.@@@.@.@@.@.@.@@.@@@@@@@@@@@...@@@.@..@@.@.@@@@@@@@@@.@@.@.@@@.@@.@@@.@.@@@...@.@. +@@@@@@.@@@..@.@@@@@@.@@.@.@@@..@@@@@@@@.@.@@@@.@@@@@@@.@@@.@@@@@@..@@@@.@.@@@@@..@@@@@@@@@@.@.@@.@...@@.@@...@@@@.@@.@.@.@@@@@.@@@.@....@@@@ +.@@@@@@...@@.@.@@@.@@@..@.@@@@@@@@..@.@@@@@@@@....@@@@@@@.@@.@@@@@@@..@@....@@@@@@@...@..@.@...@@.@@@.@@@@.@.@@@.@.@@@@@@@.@@@@@@@@@@@.@@@@@ +@..@@@@.@@@@@.....@@.@@.@@@@@@.@..@.@@.@@.@@@@@.@@@@@@@...@.@.@........@..@@..@.@@@.@.@@.@@@.@@@.@.@.@@@.@..@@@@@..@@..@@.@.@@..@.@@.@@@.@@@ +...@.@@@.@@.@.@....@@@@@..@..@@@..@@@@@..@..@@@.@...@.@@.@@.@.@@..@.@@@...@.@@@@...@.@..@@.@@.@@@.@..@@.@@.@@.@@..@@.@.@.@.@.@@@@@@@@@...@@. +...@.@.@.@.@..@@@..@.@@...@@@@@@@@@@.@..@..@.@@.@.@@@@.@@@@@..@.@.@@@...@@..@@@@......@@@.@@@@.@@.@@...@@@@@@@@@@@@@@.@.@@.@@@@.@@..@.....@@ +@.@.@.@@@...@@.@@@@@....@@.@.@.@@.@@@@.@@@@..@@.@@@@.@@.@@@@@.@@@.@@@@@@.@@@.@@.@.@...@.@.@.@@@.@@..@@@.@@..@@@.@@@..@..@@@@..@@.@..@.@@@@@. +@@.@@@...@@..@..@@@.@@@@.@@@@.@@@.@@@@..@@@@@@@@...@@..@@@@..@.@@.@@@@@@...@@@@@@@..@.@@.@@@...@@.@@...@@@@@.@..@@@.@@@.@@@@.@@@@..@.@@@@.@. +@..@@@@.@@.@@@@.@@@.@.@@@.@@@.@@@@..@@.@@..@@@.@....@.@.@@@@.@@@.@.@.@@.@@..@.@@.@@@@@@@@...@@@@@..@@@.@@@@@@.@@@@@@.@@.@@@.@@..@@@@@@@@@.@. +@@@...@@@.@@@@@@.@.@@@@@..@.@@.@@.@@.@.@.@@@@@@.@..@@.@@@.@..@.@@@@@@@@@.@@@@@.@@@.@.@.@@.....@@@@.@...@@@@@.@@...@@@@@@@@@@@..@.@@@.@@.@@@. +@@@@@.@..@.@@@@@@...@@@@..@@@@@.@...@@@@@.@.@@.@@@..@@@@@@@.@@@...@@.@@@.@@@.@@@@@@@@@@..@@.@.@@@.@@@@.@@@.@@@.@..@@@.@@@.@@@..@@@@@.@@@..@@ +.@@@.@.@@@.@@.@@@@.@.@.@@.@@@@@@@@@@@.@@@@..@@.@@@@@@.@..@@@.@@@@@@@.@@.@...@@.@.@@@@@.@..@..@@@@..@..@@@@@@@@@..@.@@.@..@@..@@@..@@@.@@.@@. +@@@.@@..@@@@@.@@@.@@@....@@.@@@@.@..@@@..@@.@@@@@..@@@@@..@.@@@@.....@@@..@@@.@.@..@...@@@@@@@@..@@@.@.@@...@@.@...@@@@@@@@.@@@.@@@.@.@.@@@@ +@@.@@..@@@@.@..@.@@@@.@@@..@@.@..@.@@@@....@@@.@..@@@@...@.@@.@@@@@@@.@.@.@@@@@.@@@..@@...@@@@@...@@@@@@@.@.@@.@@@.@.@@.@@@@@@.@.@@.@.@.@@@@ +@.@@@.@@..@@..@@@@.@@.@@@@@@@@@@@.@.@@..@@@.@@..@@.@@@@.@..@@@@@...@@..@@.@.@.@.@@@@@@.@.@@........@@@.@@.@.@@@@.@.@...@@@@....@@.@@@@.@@.@@ +.@@.@..@.@@@@@@@.@.@@@@.@@@@@@.@@@@@.@@@@.@@@..@.@@@..@@@@.@@@@@.@.@.@@@@@.@@@@@..@@@@@@@@@.@@..@@@@.@@@@..@@.@@.@@@@@@...@@@@@.@...@@@@@@@. +@@.@.@@@.@..@.@@.@.@@..@.@.@@@@..@@.@@......@.@@.@@@@@@@@..@@@@.@.@.@@@@@.@@@.@@@.@@.@@@...@....@....@@@@@@....@.@@@@@.@@..@@...@@@@@@..@@.@ +@.@@.@@@@...@@@.@@.@.@.@@.@@.@@@@..@@@@.@@@.@@@@@@@@.@.@@@@@@@@@@@@@@.@.@@@.@@.@@.@@.@@@@@@@.@@@@...@@@.@@...@@@@@@.@.@.@.@@.@@@@.@@@.@.@@@@ +@@.@.@@.@..@.@@..@..@@@@.@@@@@.@@.@.@@@.@@@.@@..@@@@...@@@@.@@..@.@@.@@@@.@@@.@@@..@@.@.@@.@..@@....@.@@@.@@@@@@.@@.@@@.@@@..@.@.@@...@@@@.. +.@@@..@@@..@.@.@@@@@.@..@@@..@@@.@@@@@.@.@..@@...@.@@@@.@@@@@@@@@.@@@..@@@@@@@@@@@@.@@@@..@@@..@..@@@@@@@@..@@@@@..@@..@@..@@@@..@@@@.@@.@@. +@@.@....@@@@@@@@..@.@@@@@@@.@@.@@@@..@@@@.@@..@..@@.@@@@..@@@@..@@...@@@@@.@@@@@@@@@..@@@@@.@@@.@@@.@..@@.@.....@@@@@.@@@@@.@@@.@@.@@@@@@@@. +.@@@.@.@..@@.@@...@.@.@.@.@.@@@@@@.@@@@@.@@@.....@@@@.@.@..@@@.@@@@@@@@.@@@@@@..@.@..@@@.@@@@@..@@@@@...@@@@@.@@@.@...@@..@@@@@@@@@@.@@@.@.@ +@..@@@@..@@..@.@@..@@@@@@@@@.@.@@.@@.@@@@@.@@@@@@@@@..@@.@@@@@@.@@@@@@..@@@.@..@@@@@@@@...@@@..@@..@@@@.@.@@@@@@....@....@@@...@@.@@@@@@@@.@ +@@@.@@@@@@.@@@.@@.@.@@.@.@..@@@@..@@@@..@@@.@.@.@@@@@@.@.@.@@@@.@...@.@@@.@.@@@@.@@.@@@@@@.@@@.@@.@@@@.@@.@@@@@@@@@@....@@.@@.@.@@.@@@@@@@.. +@@.@@.@@@....@@.@@.@@@@@@..@@@..@@@...@..@@@@@..@.@.@.@@@@@@@.@@.@@@.@@..@@@@.@..@@@.@@@@@.@.....@..@@@@@.@..@@.@@..@..@@@..@@@@@@@...@@@@@@ +@@@....@@@@@@@.@@@@@@@@@...@@.@..@.@@@@@..@..@@@@.@@@@@@.@@.@.@.@.@.@@@@.@@.@.@@@@@.@@@..@@@....@..@.@.@@.@.@.....@@@@@.@@@@.@.@@@@.@.@.@... +@@@.@.@@.@@@@....@@@@.....@.@@@..@@.@.@.@...@@@@.@@@@@@@.@@@@@.@..@.@.@.@@@.@@@@@..@@@@@.@@.@.@.@.@.@@..@.@.@@@@@@@..@...@..@@.@@@@@...@.@@@ +@@@@@@@@.@@@@@@@.@@@@@@@@@@@@.@@@@@@.@..@.@.@@..@@.@@.....@@@.@.@@@.@.@@.@..@@@.@.@@.@@@@..@@.@@@....@@@@.@@..@@@.@@@@@@@.@@@@...@@@@...@.@@ +.@@@@@@@@@.@@@@@@@..@@@@@@@@.@@@@@@@.@@@@@@@...@@@.@@@.@@.@@@.@..@@@..@@@.@..@@@@@@.@@@..@@@@@.@@@@@@@@.@@..@@@@@.@@@.@.@.@@@....@.@..@..@@@ +@@...@@@@@..@..@@.@@..@@.@@..@@.@.@@@@@@.@@@@.@@@...@@..@@@@@@@@@@@..@@@.@@@@..@@..@@@@@@@@.@@.@.@@..@@@@@@.@@..@@.@.@@@@@..@@@@@@..@@..@@.@ +@.@@@@@.@.@@@@@.@@.....@@@.@.@@@.@@@..@@@@.....@.@..@@@...@..@@.@@..@@@....@@.@.@@@@@@@@@@@@@@@..@@.@..@.@@@@@@@.@@..@.@.@@@@@@@@@@@.@@@@.@. +...@.@.@@@@@@.@@@..@@..@@@...@@..@.@..@@@@@@@@@.@@..@@..@@@@@.@.@@.@@@@@@@.@@@@@@@@.@..@.@..@@@@@@.@@@@@@.@.@@.@..@@@.@@@@@@@@@@@@@@@@.@@@@@ +.@@@..@@.@..@@@..@..@@@@..@..@@@@@@@@@@@@@@.@@@.@@@@.@@@@@.@@@....@.@@@@.@.@@@@.@.@.@.@@.@@@@.@@..@..@@@@@@...@@..@.@..@@@@.@.@@@@..@..@@@@. +@@..@..@..@@@@@.@@@....@@.@..@.@.@...@.@@.@@.@@@.@@.@@@@...@@..@@@.@@@@@@@@..@@@.@@@@@@.@@.@@.@@@@@@@.@@@@@.@@...@@@@@..@@@@@@@.@@@@...@@@@. +.@@.@@..@@@@@@..@@@@@@@@@..@...@.@@..@.@....@.@@@@.@@@....@..@...@@@@@.@..@.@.@@@.@@@@@..@@.@@@@@...@..@.@@...@@.@@@@@@@@.@@.@@@@.@.@..@.... +..@@.@..@@@.@@.@.@@..@.@@..@...@..@@.@@@@@@@@@@@@.@.....@.@@@.@@@@@...@@.@@@.@.@@@@@@.@@.@......@@.@@@..@....@@@@..@..@...@.@@@.@....@@@@@@. +@@@@.@@.@.@@...@@.@..@@@@.@@...@.@@@@@.@@@..@.@.@....@@@@.@@@@@.@@@@@@@@@..@@@.@.@..@@.@@@@@@.@.@.@.@.@.@.@@.@@@.@@@@@@.@@.@.@@.@@...@@@@.@@ +@@@@.@.@.@@@.@@..@.@@@.@@..@@@@.@.@@@@@@.@..@.@.@...@@.@@@.@.@@@@@@.@@.@.@.@.@@@@.@@@....@@@@@.@@.@@@@@.@@@@.@@@@@..@.@..@.@@@@..@@@..@@@.@@ +...@.@.@@.@@.@@.@@@.@@@..@@@@@@@@@.@@@@@@@@..@...@..@@..@.@@@@..@@@@@@.@@@@@@@@@@@@...@@.@..@@@...@..@@@@..@..@@@@@@@@..@.@@@.@@@.@@@@@@@@@@ +@.@.@@@.@@.@.@@@@@.@@@@@@@@@@@..@.@@@@@.@.@.@@@@@@@@..@.@.@@...@@.@@.@@.@@@.@@@@@.@@@.@.@@.@..@.@@@@.@@...@.@.@@.@..@....@..@@@@@@.@@.@@@@@@ +..@.@@.@@@.@@..@@.@@.@@..@@.@@@@@@.@@...@@..@@@@...@.@@@.@@@@@@@@@...@@@.@@@@@...@@.@@..@@..@..@.@.@.@@@@.@@.@..@@@@@@..@@@@@@@@@@@@@@@@@@@@ +.@@.@@.@...@@....@@.@.@@..@.@.@@.@@@@..@@@@@@...@@@@@.@....@@.@..@@@..@@.@....@@.@@@.@....@@@.@.@@@@.@..@.@.@@@@.@@...@.@.@@@@....@@.@@.@.@@ +...@@@@.@@@@.@@@.@...@..@@.@@@@.@@@@@..@.@@@@@@@....@....@.....@.@@.@.@@@@@.@@..@@@...@@@@.@@..@@..@.@@.@.@@.@.@@.@..@@@@@.@..@@.@@@.@@@@@@@ +@@.@@@..@@@.@@@..@@@.@..@@@@@@.@@@@.@@@@@@..@.@.@.@@..@@@@.@@@.@@.@@@@.@@@@@@@..@@@@@@@@..@...@@@@@@.@@@....@@@@.@@@@@.@@@.@@@@@@@@.@@...@@@ +..@.@@@@..@@....@@@.@@.....@@@@@@@@.@..@.@..@@...@.@..@@@.@@@.@...@@...@@@@.@.@@.@@@...@..@@@.@..@.@@@@@.@@...@@@..@..@@@..@@.@@@@@@..@@@@@@ +.@...@.@@..@@@.@.@@.@@...@.@@@@.@@@@@@..@@.@@@@....@..@.@@.@@.@@.@@@.@.@@@@.@.@@..@@@@@..@.@@.@.@@.@@@@...@@...@.@.@@@.@@@.@@.@@@@@@@.@@@@@. +@@..@@@@@.@...@..@..@@@..@@@.@@@@..@.@@.@@@@.@@.@@@@...@..@@@@@@@@@@.@@@@@@.....@@....@@...@@@@@..@@@.@@@@@@@@.@@@...@.@@.@@..@.@..@.@@@@@@@ +.@..@@..@...@@.@@@.@.@..@@..@.@.@.@..@@@@@@..@..@..@@@@@@.@@.....@.@@@@@@@.@.@.@@.@@@@...@@@@@@.@.@@.@@@@@.@..@@.@.@@@@@@@@@@@@..@@@@.@.@.@. +@...@@@@@...@@@@@@.@@.@...@.@@@@@@@@@@..@.@@@..@@.@@@..@@@@@@..@@@@@.@@..@@@@@@@@.@@@@@@@.@.@@@@.@@@@@@@...@@@@@@.@.@.@@@@..@@..@.@.@@@@@@.@ +.@..@@.@@.@@@.@@.@@...@@@.@..@.@@.@@@..@@..@@@.@..@@@@@.@.@@..@.@..@...@...@...@@.@.@.@.@@.@@.@@.@@@@..@@@..@@.@@.....@@@@.@...@@.@...@.@@.. +@@.@@.@@.@@@@@@@.@@.@..@@@@@@@.@...@.@@@..@@..@@.@@@@..@@@@@@.@@@@@.@@@@@@@.@.@.@.@.@.@.@.@@@@@@@..@@@.@@@.@@.@.@@@..@@@.@@@.@@@@.@@@@.@.@.. +@@.@..@@@..@..@.@@@.@@@@@@.@.@@@@@@@@@..@@.@@@@.@.@.@@.@@.@@@@@@..@...@.@@@@@@@@@@@@.......@@@..@...@@@@@@@..@.@@@@@@@@@....@@@@@@@@@@.@@... +..@.@@@.@@..@@...@.@@@@...@.@@@@..@@@.@..@.@...@@@.@@.@@@@@.@.@@.@@@.@@.@@@@@.@@@.@@.@@@..@.@..@@@@@@@..@@@@@...@....@.@@.@@@..@@@@.@@.@@@@@ +@@@.@.@.@@@@@@@@@@@...@..@@@@...@@@@@.@...@@@@@@.@@@..@@@@..@@@@@@@@@@@@@@@@.@@@..@@.@@@@...@..@......@.....@@@.@@@@@@@@@.@@@..@@@@@.@@@.@.@ +@.@.@@.@@.@.@..@.@@.@@@@@..@..@@@@@@.@@@@.@@@@@.@@@@@@..@@@..@@@@@@.@.@@....@..@@@.@@@..@@@@...@@.@@@@@@@@.@@.@.@.@.@@.@.@.@.@@@@@@@..@@@..@ +@@@@@@@..@.@@@.@@.@..@@....@.@@.@@.@@@.....@@@@@@@.@@.@.@@..@@@@@@@...@...@.@@@@@..@@@@@@.@@@@.@@...@@@...@@@@@@.@@@@.@.@@.@....@@@.@@@@@... +@....@@.@.@.@...@@@..@.@@@.@@@@@.@@@.@...@@.@@.@@..@.@....@.@@.@.@.@.@.@@.@@@@.@@.@@..@@@@@@@@@..@.@@@.@@.@.@@@@@@@@@@@@.@.@...@..@.@@@..@@@ +.@@.@@....@@@.@@@..@.@.@..@.@@..@..@@.@@..@.@@@@@@.@@.@@@@@.@...@@@@@.....@@@....@.@@.@@@@@@.@@@@...@@.@@.@@.@@@@@@@@@.@@@@...@@.@.@@.@@@.@@ +..@@@.@@@.@@@..@@...@@@@@@@@@@.@.@@@@@...@@.@@@@@.@@@..@.@...@@.@@.@@.@@.@@@@@.@.@@@..@@@..@@.@.@..@@@..@@@@.@@@@@@...@@.@@.@.@..@@.@@@.@@@. +.@@@.@@@@@@.@@@@@@.@@.@..@.@@@..@@.@@@@.@@@.....@@.@@.@.@.@@@.@@..@@@@@@.@@.@@...@.@@@@@@@.@@@..@.@@..@@@@..@.@@@.@@@@@@@@@.@@@@.@@@@.@@@@@. +@@.@@@.@@@@.@@.@@@@.@@@..@@@@@@@.@...@@.@@..@@@@@.@@@@@@.@...@@.@@.@@@@@.@@@.@@@@@@..@.@@@@@@@@@.@@@.@@.@.@.@@@.....@..@@.@@.@@...@.@..@..@@ +.@@...@@@@.@@.@@@@@@@.....@@@@@@.@.@.@.@@@@@@@@...@.@.@.@@.@@.@.@.@@.@@@@.@@.@.@@@@@..@@@@...@@@@@.@@@@@.@..@@@.@@@@@..@@@@@@.@@@..@.@@...@. +@@@@@@@@@.@@@@@.@@@@..@.@@@@@@@....@@@@......@.@.@.@@@.@.@.@@@.@.@@.@@.@@@@.@@..@..@@@@@@.@@@.@@@@@@@@@@@@..@@@.@@...@..@.@.@.@..@@.@@.@@.@@ +@@....@@@...@@@@..@.@.@.@@@...@@@.....@@......@.@@.@@@..@@@@@@.@@...@.@@@@@@@@.@....@@..@...@.@@...@@@@@@..@@.@@.@@@.@.@@.@.@.@....@..@@.@@. +@.@...@@@..@@@@@@@@...@...@@@@.@@@@...@..@.@.@@.@@@@@.@@@@@.@@.@@.@..@@.@@..@@....@@.@@@@@.@@@@@@@..@@@@@..@.@@.@@@.@@.....@@@@.@.@.@@.@@@@@ +@@@@.@@..@.@.@....@@@@.@@.@@...@@..@@@@@@.@@.@..@@@@@.@@@..@@@.@@@..@@@@@@..@@..@@...@@@..@@@.@@.@@..@@.@@@@....@......@.@@@.@@@@@.@@.@@..@@ +@@@@@.@@.@@@@.@..@@..@...@@@@.@@..@@@@@.@@.@@@@@.......@@..@@@@@@@..@.@.@@.@@@@@@@.....@.@@@.@@@@@.@...@@.@@@@@.@@@.@@@@@@@.@@@.@...@.@.@... +.@@..@@.@@..@@@.@@..@@.@@@.@.@.@@@..@..@@@.@@@@@.@.@.@.@.@.@@@..@@..@@.@...@@@..@...@@@.@@@@.@@@@@...@@@..@.@@.@.@.@@.@@@@@@.@@@.@.@@.@.@.@@ +.@@...@@....@@@@@@.@....@@@@@.@.@.@@.@@@@.@.@@@@@.@@@@@@@@....@@@.@.@@...@@@@@.@@@@@@.@..@@.@@.@@@@@@@@..@@.@.@@@..@@@@@@@@.@@..@@@.@@@.@@.@ +.@.@@@.@@@.@.@@...@..@@@@@@...@@@@..@@@@@@@@.@.@@.@@@.@.@@@@..@.@@.@@@@@.@@@@@.@@@@..@@@@@@@@.@@.@@@.@..@@@@@.@@..@@..@.@@@@.@..@.@..@@..... +...@@..@@.@@@.@.@@@@@@@@@..@@@@@@..@.@@@@......@...@.@...@.@@@.@@....@@.....@@.@@..@..@@@@...@..@@..@@..@@.@.@@@.@.@.@@.@.@@.@..@@..@@..@@@@ +.@@@@@@@.@.@@@@@@@@.@@@@@@..@@....@.@@@@@...@@@@@.@.@.@@..@@@@@..@@@@@@@.@@.@@.@@@...@@.@.@@@@.@@@@@.....@..@.@@.@@.@.@..@@@.@.@.@..@@..@@@. +@@@@@@@@..@@.@@.@.@@@@@@.@@.@@@@@.@...@@@@...@.....@@@....@@.@@@@@@@..@@@.@@@@@....@@..@@.@@@@.@@.@@@@@@@.@...@@.@@@.@.@@@@@@.@...@...@@.@@. +@@.@.@@@..@@@.@.@@.@@@.@...@@..@@@.@.@.@@@.@.@...@@.@@@@@@@.@@.@@@@@..@@@@.@@@.@@@.@@@@@@@..@.@@.@@.@..@@@@@.@..@.@..@@@....@..@..@@@@.@@..@ +@.@@@.@@@.@...@@@.@@@@@@@.@@@.@...@.@@@@...@@@@@.@@@@@@@@@@..@@@@@.@@@@.@@@.@@.@@.@..@@.@@@@@.@@@.@@@@@.@@.@@@.@.@.@.@.@.@@@@...@..@@@@@..@@ +...@@@@@.@.@.@@@@......@..@.@@@@@@@.@@@@@@.@@@.@..@@@..@.@@@.@.@@@@@@@.@.@@@@..@@.@@@@@@@@@@..@@@@@@@@..@..@..@@@@...@@@..@..@.@@.@@.@.@.@@. +@...@.@@@.@@.@@..@@.@@...@@@.@.@@.@@@@.@..@@@@@@@@@.@.@@.@@@@@@.@@.@.@@..@@@..@@@@..@@....@.@@@.@@@..@@@.@..@@@@@@@@@@.@.@@@.@....@@@@.@@@.@ +@@@.@.@@@@@..@.@.@.@@.@..@@...@@@@..@@.@....@@.@.@@@@.@@.@@@.@@.@.@@.@.@.@.@@..@@..@@@@@@@@@.@@@@@@.@@@@@..@@.@@.@@@.@@.@.@@@@.@..@@.@@..... +.....@@@@@@..@@..@....@@@@@@@..@@@@..@.@.@.@@.@....@@@@@.@@...@..@@.@.@..@@@..@.@@@@...@@@.@@@@@@@@@@@@.@.@@@.@.@@@..@@@@.@.@@.@@@@....@@@@. +....@@.@.@.@@@..@@@.@@@@@@@@@.@..@.@.@@@.@...@@@@.@@.@.@@.@..@..@@@@@@@...@@@...@.@@.@@@@@@@..@@@@@@@.@@.@@@@@@.@....@.@@.@.@@.@@@@.@@@@...@ +.@@@.@@@@@@..@.@@@@.@@.@.@@@.@@@@@@@@.@@@@@@@@@@@.@@..@@@@@...@@@@@@@@@.@@@@@@@.@..@@@@@.@@@@@@@@@@@....@@@.@@@.@@@@@@.@@@.@@@.....@@@.@@@.@ +.....@@@@.@@.@..@@@@@@@@.@@@@.@@@@..@@@@.@@@..@.@@@.@@.@.@@.@@@@..@@@..@@@@@@...@@@.@..@@...@@@.@@@@@.@@..@..@.@@@@@.@@.@@.@..@....@@.@..@.@ +.@.@.@@.@@@.@@.@.@@@@@......@@@....@...@.@@@@..@@@..@.@.@@@.@.@@.@@@.@..@.@@@.@@...@.@@.@.@.@@@@@@..@@@@@@@.@@.@@@.@.@..@@@@..@@@.@@.@..@.@. +@.@.@@@@.@.....@@..@.@@@.@.@..@@@.@.@..@.@@@@@@@.@@@@@..@@..@@@@@.@@...@@.@@@.@@.@.@@@@@@@@@@@@...@@@.@@@@@.@@@@@@.@@.@@@@@@..@.@@@...@@@@.. +@@@@@.@.@.@.@@@@@@@.@.@@@@..@@@@.@@.@@...@@.@@...@@@.@@.@.@@@@@.@@@@@@@..@@@@@@..@@.@@.@.@@.@.@@@@@@@@.@@@@...@@..@@@.@..@..@@.@..@@@..@@@@. +.@.@.@.@@@@@@@@@.@@.@@.@@@.@@@@@..@.@..@@@.@@@..@@.@@.@@@....@@@@@....@@@@@.@@@@@@@@.@@.@..@@.@...@.@.@.@@..@@.@.@.@@@.@@.@@@@@..@@@.@@@@@.. +@@@.@@.@@@.@@@@@..@@@@.@@@.@@@@@.@@..@@.@.@..@@.@@.@@.@@..@@@@@@.@@@@@.@.@.@..@@@.@@@....@@.@@..@@@@@@@@@@.@.@@@@@@...@.@@..@@@@..@@@@.@.@@@ +.@@@..@@@.@.@@@@@@.@.@@@@.@@@@@@.@@@@@.@@@@@@.@@@@.@@.@@@@@@@@@@@@@@@@@@@.@@@..@@@@@@..@..@@.@@@@@@@..@....@@..@.@@.@@.@@..@@@.@.@@..@@..@@. +@@@.@.@@@@.@@@@@@.@@.@.@@..@@@..@@@..@.@.@.@@@@@@@@@@@@..@@@@@@@@@@@.@@@@@@..@.@@@@....@@@@@@...@@.@@@.@.@@@@.@.@.@@.@@@@@....@@@@..@@.@@@@@ +.@@@@@@@@@.@.@@.@.@.@@..@@@.@..@@@.@@@@@.@@@..@@@..@@@@@@@@@@@@.@@@.@@@@@@...@@.@@...@@@@.@....@..@@..@@.@@@.@@@.@..@.@@@@.@.@@@@.@....@@@@@ +@.@@.@@@@@.@@.@@@@@@@@@@..@@@@@@@@..@.@..@@@@.@.@.@@@@@@.@@@@@..@.@@@..@@@@.@@.@.@@@@.@.@@@@@@@@.@@@.@@@@@.@@@...@@@@....@.@@.@.@...@..@.@@@ +..@@...@@@@@@@.@.@@..@@@@@@@....@@.@@..@..@@@.@..@@.@.@@@@@@@@@@...@...@@@@@@@.@.@@@@@@.@....@@@@......@@@.@@...@@@@@@..@@@@@@@@@@.@@@@@@@.. +@@.@@..@@@@@@@@.@.@@.@@@.@.@@@@@@@.@@@@@@@.@@.@..@@@.@...@.@@@@...@..@@...@@@@@@.@@@@@.@@@..@@@@.@@@@@@...@@@.@.@..@..@@@@@.@.@.@.@@..@@@... +@@.@@@@.@.@.@@.@.@.@...@@@..@..@@@@@.@...@@@@.@.@@.@@..@@@..@@...@@@..@@@..@@@.@@.@.@.@.@.@@@@@..@@@@..@@@@@@..@@@@@@@@@@.@.@..@@@.@@@..@.@. +...@@@@@@@@@@@.@..@@...@@@@@@@@.@@@.@@@.@.@@@@.@@...@.@@..@@@@@..@.@@@..@.@@@@@.@..@@.@@@@@@@.@@@@@@@..@@@@.@...@.@@@@@@..@.@@@@@@@.@..@.@@. +..@@.@@@.@.@.@@@.@@.@.@.@@@.@@@@@@@.@@..@..@@@@@@@@.@@.@@@..@@..@@@@@.@@@@.@.@.@@@..@..@@...@...@@@@.....@@@.@.@.@..@.@@@@@@@@@@...@..@@@@@@ +@@...@@@@@@@@.@@@@.@.....@@@@@@@@.@@...@@@@@.@@@..@....@@....@.@@.@@@.@.@@@@@@..@...@..@@.@@@@@@@@@@@@@@...@@@@@@.@@@@@@@.@@.@.@@@.@@@@.@@@@ +@@@@...@@@@.@@.@...@@.@@@@..@@.@@.@@@@.@.@@..@@.@.@.@.@.@@@@....@..@@@@.@@@@@@@@@@@...@@.@.@.@@@@@@.....@@@@@@.@@@@@@.@.@..@@@@@.@...@@..@@@ +@..@.@@@...@@@@.@@@@@@.@@@.@.@@@..@...@.@@@@@.@.@@@@@@@@@@..@@@@..@@@.@@@@@@@@@@@@@@.@@@@@@@@@@@@..@@.@...@@.@@@..@@@@.@@@@@...@.@@@.@@..@@. +.@..@@..@..@@@@.@.@@.@@@@@.@@...@@@.@..@@@@@@@@..@..@@@@@@@.@@@@@@@@@@@.@@@@@@.@@..@@@@.@.@@.@@..@.@@@@.@@@.@@@@...@@@.@.@@@....@@@.@.@@@@@@ +@@@@.@.@.@@@@@@@@.@@@@@.@@...@@@@@.@@.@@...@@@@@@..@@@@@@@.@..@...@@@.@.@.@@@...@@@.@..@@.@@@@...@@@@@..@@..@@@.@@@.@.@.@@@@@@@@.@.@@@@@@@.. +.@@..@@..@@@@@@@@@@.@.@@@..@@@@@..@@.@@.@.@.@.@@@@.@@@@@@......@.@@@.@..@@....@.@.@@@@..@.@.@@@@@@@..@@@@..@@@@@.@@..@@.@.@@@.@..@.@@@@...@@ +.@.@@.@@@@@....@@@@...@@@@@.@@@.@.@@@@@@@...@.@@@@@@.@@@@@@.@@@@@.@..@.@@.@@..@.@...@@@.@..@@@..@..@.@...@@......@.@.@@@@@@..@@@@@@@.@@..@.@ +.@@.@@..@@@.....@.@@..@.@@@@.@.@@@@@.@@@@...@@@@.@.@...@.@@.@@.@......@.@@.@.@@..@@..@.@@@@.@@@.@..@.@@@@.@@@@.@@@@@@@@@.@@.@@.@@@@@@@@@@@.@ +@@@@.@@.@@@@.@@@..@@@@@@@@.@@@.@@@@@@@@@@....@@.@.@@.@@.@.@.@@@@.@@.@.@@@@..@@.@....@@@@@.@@.@@.@@.@.@@@@@@.@@@@@@@@..@.@...@@..@@@@..@@@@@@ +@.@.@..@@.@.@@@@.@@@.@@.@@...@@@@.@@.@.@@..@@..@@.@@.@.@.@@@@.@@.@..@@@@@@.....@@@.@.@@@@@@.@@@.@.@..@.@@@.@....@@@@@.@@@@.@@.@@@.@....@.@@. +@@.@.@@@.@@@.@@.@.@@@@@@@.@@.@@.@@.@.@.@..@@@@@@.@@@.@.@@@.@...@@@@@.@.@@.@.@...@@@@.@@.@@.@.....@.@@....@@.@..@@@@@@@@@.@.@@@@....@@@@.@.@@ +@@@@@.@.@.@..@.....@@@@@@.@.@..@.@.@@@..@@@@@@@@@@.@@.@@..@.@@@@@.@@@@@@@@@@..@@.@@@@.@@.@@.@@@.@@.@@@.@@@@.@@@.@@@.@.@@@@..@@@.@.@@@.@..@@@ +..@..@@@@@@@@....@@@...@@@@..@@...@@.@@@@@@....@.@@@@@@@..@@@@..@@@@@@.@@@.@.@@.@@@@@@@@@@...@.@.@@...@.@@@..@..@.@.@@@@@.@@.@@.@@....@@@.@@ +@@.@.@.@@@@@@..@@.@.@@.@@.@@@..@@@@@@@@.@.@@@@@@.@@.@@...@...@@..@..@@@@...@.@@@@.@@@@@.@@.@@@@@..@.@.@.@@.@@@@@.@@@.@@.@.@.@..@..@@.@@..@@@ +@@@@.@@@@..@.@@@@@@@@.@.@..@..@.@...@.@@@@@@@@.@@..@@@@@.@@@@.@...@.@.@@@@..@.@@@.@@@.@@..@@@@@..@@@@..@@@@@@@...@..@.@.@@.@@.@@.@@...@@@..@ +@@@.@@@@@@@@@.@@@@@.@@@@@@@@@@.@@@@.@@.@....@.@.@.@@@.@..@@.@@.@....@@.@@@...@.@..@.@@@@@.@@@@.@@.@@@@@@.@@@..@.@@..@@@.@@.@@@.@.@.@@@@.@@@@ +.@@@@@....@.@@@@@@@@..@.@@.@.@.@.@@.@@@...@.@@@@@@@..@@@.....@@....@@@@@.@@.@..@@@.@@@.@@.@@@@@@@...@.@..@@@@@@@@@@@@@@.@@@@@..@@@@..@@@@.@@ +@@@@@@@.@@@@.@@@@.@@.@@@.@..@@.@@@@@.@.@@@@@@.@..@.@.@...@@@..@.@...@.@@.@@@.@@...@@..@...@@@.@.@..@@@.@@@@@@@@@@.@.@..@@.@.@@@@@.@@@..@@@.. +@@@.@..@@@@@...@..@@@.@@@@.@@.@.@@@@@@..@@.@.@.@@.@@@@@@.@...@@@..@.@@@.@@@@@.@@@.@@@....@.@@.@.@@@@.@.@@@@.@@..@@@.@.@@.@@..@@@@@..@@@...@@ \ No newline at end of file diff --git a/run_tests.cpp b/run_tests.cpp index b6e955d..44874c3 100644 --- a/run_tests.cpp +++ b/run_tests.cpp @@ -7,3 +7,4 @@ #include "day1.cpp" #include "day2.cpp" #include "day3.cpp" +#include "day4.cpp" diff --git a/utils.h b/utils.h new file mode 100644 index 0000000..10ed4cc --- /dev/null +++ b/utils.h @@ -0,0 +1,19 @@ +// +// Created by Grant Horner on 12/4/25. +// + +#pragma once +#include +#include +#include + +constexpr std::string_view to_string_view(const std::ranges::subrange cs) { + return std::string_view{cs.data(), cs.size()}; +} + +inline std::string read_file(std::string_view path) { + std::ifstream input(path.data()); + std::stringstream buffer; + buffer << input.rdbuf(); + return buffer.str(); +}