#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"( 11-22,95-115,998-1012,1188511880-1188511890,222220-222224, 1698522-1698528,446443-446449,38593856-38593862,565653-565659, 824824821-824824827,2121212118-2121212124 )"; 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 ids_str = str | std::views::split(","sv) | std::views::transform([](auto const& str) { std::vector range{}; range.resize(2); // std::ranges::transform( // aoc::trim(std::string{std::begin(str), std::end(str)}) | std::views::split("-"sv), // std::begin(range), // [](auto const& value) { // return aoc::trim(std::string{std::begin(value), std::end(value)}); // }); std::ranges::transform( aoc::trim(std::string{std::begin(str), std::end(str)}) | std::views::split("-"sv), std::begin(range), [](auto const& value) { return u64(std::stoul(aoc::trim(std::string{std::begin(value), std::end(value)}))); }); return range; }) | std::ranges::to(); auto is_valid_id = [](u64 id) { auto const str = fmt::format("{}", id); if (str.size() % 2 != 0) return true; bool is_invalid = true; for (usize i = 0; i < str.size() / 2; ++i) { if (str[i] != str[str.size() / 2 + i]) { is_invalid = false; continue; } } return !is_invalid; }; u64 sum = 0; for (auto const& id : ids_str) { u64 const start = id[0]; u64 const end = id[1]; fmt::print("{} -> {}: ", id[0], id[1]); for (u64 i = start; i <= end; ++i) { if (!is_valid_id(i)) { fmt::print("{}, ", i); sum += i; } } fmt::print("\n"); } 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; }