From ed04586b1d1e852855df2d91f71564aadaaea8e9 Mon Sep 17 00:00:00 2001 From: mnerv <24420859+mnerv@users.noreply.github.com> Date: Sun, 14 Dec 2025 18:43:39 +0100 Subject: [PATCH] 2025 day 07 p1 --- 2025/CMakeLists.txt | 1 + 2025/day07.cpp | 108 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 2025/day07.cpp diff --git a/2025/CMakeLists.txt b/2025/CMakeLists.txt index 1aab3c0..17de4cc 100644 --- a/2025/CMakeLists.txt +++ b/2025/CMakeLists.txt @@ -34,4 +34,5 @@ add_day_executables( "day04.cpp" "day05.cpp" "day06.cpp" + "day07.cpp" ) diff --git a/2025/day07.cpp b/2025/day07.cpp new file mode 100644 index 0000000..645ecf2 --- /dev/null +++ b/2025/day07.cpp @@ -0,0 +1,108 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "fmt/std.h" + +#include "aoc/types.hpp" +#include "aoc/utils.hpp" + +using namespace std::string_view_literals; +using namespace aoc::types; + +// starts at 50 +[[maybe_unused]]constexpr auto raw_str = R"( +.......S....... +............... +.......^....... +............... +......^.^...... +............... +.....^.^.^..... +............... +....^.^...^.... +............... +...^.^...^.^... +............... +..^...^.....^.. +............... +.^.^.^.^.^...^. +............... +)"; + +static auto entry([[maybe_unused]]std::span const& args) -> void { + // std::string str{raw_str}; + auto str = aoc::read_text("./input.txt").value_or(""); + str = aoc::trim(str); + + auto mat = str | std::views::split("\n"sv) | std::views::transform([](auto line) { + return line | std::views::split(""sv) + | std::views::transform([](auto tok) { + return std::string{std::begin(tok), std::end(tok)}; + }) + | std::ranges::to(); + }) | std::ranges::to(); + + struct beam { + usize row; + usize col; + }; + + std::vector beams{}; + for (usize i = 0; i < mat.size(); ++i) { + for (usize j = 0; j < mat[i].size(); ++j) { + if (mat[i][j] == "S") { + beams.push_back({i, j}); + break; + } + + auto const size = beams.size(); + for (usize k = 0; k < size; ++k) { + if (beams[k].row == i - 1 && beams[k].col == j) { + if (mat[i][j] == ".") { + mat[i][j] = "|"; + beams[k] = {i, j}; + } else if (mat[i][j] == "^") { + beams[k] = {i, j - 1}; + beams.push_back({i, j + 1}); + mat[i][j - 1] = "|"; + mat[i][j + 1] = "|"; + } + } + } + } + } + + f64 sum = 0.0; + for (usize i = 0; i < mat.size(); ++i) { + for (usize j = 0; j < mat[i].size(); ++j) { + if (mat[i][j] == "^") { + if (mat[i - 1][j] == "|") sum += 1; + } + } + } + + fmt::print("res: {}\n", sum); + + // for (auto const& row : mat) { + // for (auto const& col : row) { + // fmt::print("{}", col); + // } + // fmt::print("\n"); + // } +} + +auto main([[maybe_unused]]int argc, [[maybe_unused]]char const* argv[]) -> int { + try { + entry({argv, std::next(argv, argc)}); + } catch (std::exception const& e) { + fmt::print(stderr, "{}\n", e.what()); + return 1; + } + return 0; +}