#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"( 987654321111111 811111111111119 234234234234278 818181911112111 )"; 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); fmt::print("INPUT\n"); fmt::print("⎻⎼⎽⎼⎻⎺⎻⎼⎽⎼⎻⎺⎻⎼⎽⎼⎻⎺⎻⎼⎽⎼⎻⎺⎻⎼⎽⎼⎻⎺⎻⎼⎽⎼⎻⎺⎻⎼⎽⎼⎻⎺⎻⎼⎽⎼⎻⎺⎻⎼⎽⎼⎻⎺⎻⎼⎽⎼⎻⎺⎻⎼⎽⎼⎻⎺⎻⎼⎽⎼⎻⎺⎻⎼⎽⎼⎻⎺⎻⎼\n"); fmt::print("{}\n", str); fmt::print("{}\n", std::string(80, '-')); auto jolts_str = str | std::views::split("\n"sv) | std::views::transform([](auto const& str) { return aoc::trim(std::string{std::begin(str), std::end(str)}); }) | std::ranges::to(); std::vector jolts{}; jolts.reserve(jolts_str.size()); for (auto const& jolt : jolts_str) { u64 largest = 0; for (usize i = 0; i < jolt.size(); ++i) { for (usize j = i + 1; j < jolt.size(); ++j) { auto const value = std::stoull(fmt::format("{}{}", jolt[i], jolt[j])); if (value > largest) largest = value; } } jolts.push_back(largest); } for (auto const& jolt : jolts) { fmt::print("{}\n", jolt); } auto sum = std::ranges::fold_left(jolts, u64(0), [&](auto a, auto v) { return a + v; }); fmt::print("res: {}\n", sum); } 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; }