#include #include #include #include #include "aoc.hpp" #include "aoc/utils.hpp" #include "fmt/format.h" using namespace aoc::types; using namespace std::string_view_literals; namespace lpf { using edge_t = std::pair; using edges_t = std::vector; class node { public: node(i32 id, i32 value, edges_t const& edges) : m_id(id), m_value(value), m_edges(edges) {} auto operator==(node const& other) const -> bool { return m_id == other.m_id && m_value == other.m_value; } auto id() const -> i32 { return m_id; } auto value() const -> i32 { return m_value; } auto edges() const -> edges_t const& { return m_edges; } private: i32 m_id; i32 m_value; edges_t m_edges; }; class trail { public: trail(std::string const& str) { auto lines = str | std::views::split("\n"sv) | std::views::transform( [](auto const& c_str) { return std::string_view( std::begin(c_str), std::end(c_str) ); }) | std::views::filter([](auto const& strv) { return !strv.empty(); }) | std::ranges::to(); m_rows = lines.size(); m_cols = std::begin(lines)->size(); std::ranges::for_each(lines, [&](auto const& str) { std::ranges::for_each(str, [&](auto const& ch) { if (std::isdigit(ch)) m_data.emplace_back(ch - '0'); else m_data.emplace_back(0xFF); }); }); } auto at(usize row, usize col) const -> u8 { if (row >= m_rows || col >= m_cols) return 0; return m_data[row * m_cols + col]; } auto rows() const -> usize { return m_rows; } auto cols() const -> usize { return m_cols; } auto data() const -> std::vector const& { return m_data; } private: usize m_rows; usize m_cols; std::vector m_data; }; } auto aoc24::day10([[maybe_unused]]std::span const& args) -> std::expected { auto res = aoc::read_text("./dat/24/ex/10a.txt"); if (!res) return std::unexpected(res.error()); auto const txt = *res; lpf::trail trail{txt}; return {}; }