diff --git a/dat/24/ex/10a.txt b/dat/24/ex/10a.txt new file mode 100644 index 0000000..a305b9d --- /dev/null +++ b/dat/24/ex/10a.txt @@ -0,0 +1,4 @@ +0123 +1234 +8765 +9876 diff --git a/dat/24/ex/10b.txt b/dat/24/ex/10b.txt new file mode 100644 index 0000000..db56de0 --- /dev/null +++ b/dat/24/ex/10b.txt @@ -0,0 +1,7 @@ +...0... +...1... +...2... +6543456 +7.....7 +8.....8 +9.....9 diff --git a/dat/24/ex/10c.txt b/dat/24/ex/10c.txt new file mode 100644 index 0000000..17655af --- /dev/null +++ b/dat/24/ex/10c.txt @@ -0,0 +1,7 @@ +..90..9 +...1.98 +...2..7 +6543456 +765.987 +876.... +987.... diff --git a/dat/24/ex/10d.txt b/dat/24/ex/10d.txt new file mode 100644 index 0000000..185787f --- /dev/null +++ b/dat/24/ex/10d.txt @@ -0,0 +1,7 @@ +10..9.. +2...8.. +3...7.. +4567654 +...8..3 +...9..2 +.....01 diff --git a/dat/24/ex/10e.txt b/dat/24/ex/10e.txt new file mode 100644 index 0000000..cada9b3 --- /dev/null +++ b/dat/24/ex/10e.txt @@ -0,0 +1,8 @@ +89010123 +78121874 +87430965 +96549874 +45678903 +32019012 +01329801 +10456732 diff --git a/dat/24/re/10.txt b/dat/24/re/10.txt new file mode 100644 index 0000000..ebf45d3 --- /dev/null +++ b/dat/24/re/10.txt @@ -0,0 +1,40 @@ +6541001098012789610347890107654656710323 +7832102127643898701256521218323465891410 +8996543034556789650987434309012534892565 +3887689678965876501874345892105621763676 +4305678563456903416765676756898760654980 +5214107852107812321254382347872108901221 +6543236943056921010341291078963457654338 +7896545987045430010980012569454968983549 +3217830656189899121676101430356879892678 +2106921043210778234585232321267898761432 +3478854430345665056798743410456901050501 +4569763521012552143895654501345012347670 +3654012678903443212104309690432167898981 +2783656987654874908765218781201254012567 +1092347897893965889034765670387063013498 +1001298756102456776121874989496122110901 +2310891043201307655430923876565434325892 +3456780103011218967649810189410145456743 +2561078212320989858236702107320236787654 +1232569343423874749145893678741199899873 +0343454358514565632098704569632087684562 +0456789969609034501347612189323456893001 +1499876878798123101256543079012548762110 +2387905462687678871212344568187659450223 +3456012301056549960305650127691098321054 +3456732102345832154454781034540107650169 +2369847898738981023763692321121256743278 +1078456654567670119832103400012349894361 +0012387763456543208041076510123412765010 +7650196892565454589107889623296503854321 +8943256781074303673236908774387654983432 +8912965890985210984365219985345015676541 +7607834187866789875434308776236723498650 +6506543045679012766923105698109894567743 +5410432134988703457810014567056210754892 +0322345028767845893456723459847349889701 +1201276719454936712679801210738256776545 +2450989805103221604589752345629145480230 +2347823456012120113298943238710076591121 +1056910147893012320107654109656789432012 diff --git a/sol/24/CMakeLists.txt b/sol/24/CMakeLists.txt index 1452b3d..339a40a 100644 --- a/sol/24/CMakeLists.txt +++ b/sol/24/CMakeLists.txt @@ -4,13 +4,15 @@ set(HEADERS set(SOURCES "aoc.cpp" "day01.cpp" - "day02.cpp" + # "day02.cpp" "day03.cpp" - "day04.cpp" + # "day04.cpp" "day05.cpp" "day06.cpp" "day07.cpp" "day08.cpp" + "day09.cpp" + "day10.cpp" ) add_library(aoc24 STATIC ${HEADERS} ${SOURCES}) target_include_directories(aoc24 diff --git a/sol/24/aoc.cpp b/sol/24/aoc.cpp index ad48766..99e9e03 100644 --- a/sol/24/aoc.cpp +++ b/sol/24/aoc.cpp @@ -19,13 +19,15 @@ auto entry([[maybe_unused]]std::span const& args) -> std::expected< switch (day) { case 1: return day01(args); - case 2: return day02(args); + // case 2: return day02(args); case 3: return day03(args); - case 4: return day04(args); + // case 4: return day04(args); case 5: return day05(args); case 6: return day06(args); case 7: return day07(args); case 8: return day08(args); + // case 9: return day09(args); + case 10: return day10(args); default: return aoc::make_error(fmt::format("day {}", day), std::errc::not_supported); } diff --git a/sol/24/day07.cpp b/sol/24/day07.cpp index 65ad9bc..9435b2c 100644 --- a/sol/24/day07.cpp +++ b/sol/24/day07.cpp @@ -6,7 +6,7 @@ namespace rbr { } auto aoc24::day07([[maybe_unused]]std::span const& args) -> std::expected { - auto res = aoc::read_text("./dat/24/re/07.txt"); + auto res = aoc::read_text("./dat/24/ex/07.txt"); if (!res) return std::unexpected(res.error()); auto const txt = *res; diff --git a/sol/24/day08.cpp b/sol/24/day08.cpp index 9d15ced..c6d84e4 100644 --- a/sol/24/day08.cpp +++ b/sol/24/day08.cpp @@ -3,5 +3,5 @@ #include "fmt/format.h" auto aoc24::day08([[maybe_unused]]std::span const& args) -> std::expected { - return aoc::make_error("day 8", std::errc::not_supported); + return aoc::make_error("", std::errc::not_supported); } diff --git a/sol/24/day09.cpp b/sol/24/day09.cpp new file mode 100644 index 0000000..e1e7bf9 --- /dev/null +++ b/sol/24/day09.cpp @@ -0,0 +1,7 @@ +#include "aoc.hpp" +#include "aoc/utils.hpp" +#include "fmt/format.h" + +auto aoc24::day09([[maybe_unused]]std::span const& args) -> std::expected { + return aoc::make_error("", std::errc::not_supported); +} diff --git a/sol/24/day10.cpp b/sol/24/day10.cpp new file mode 100644 index 0000000..c5d1708 --- /dev/null +++ b/sol/24/day10.cpp @@ -0,0 +1,84 @@ +#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 {}; +}