54 lines
1.6 KiB
C++
54 lines
1.6 KiB
C++
#include <span>
|
|
#include <vector>
|
|
#include <fstream>
|
|
#include <expected>
|
|
#include <system_error>
|
|
#include <ranges>
|
|
|
|
#include "fmt/format.h"
|
|
|
|
#include "aoc/aoc.hpp"
|
|
|
|
namespace vfp {
|
|
using namespace aoc::types;
|
|
using page_order_rule = std::vector<i32>;
|
|
|
|
class manual_updates {};
|
|
}
|
|
|
|
auto entry([[maybe_unused]]std::span<char const*> const& args) -> std::expected<void, aoc::error> {
|
|
using namespace std::string_view_literals;
|
|
auto txtres = aoc::read_text("./dat/24/ex/05.txt");
|
|
if (!txtres) return std::unexpected(txtres.error());
|
|
auto const txt = *txtres;
|
|
|
|
auto const not_empty = [](auto const& str) { return !str.empty(); };
|
|
auto lines = txt | std::views::split("\n"sv)
|
|
| std::views::transform([](auto const& str) { return std::string_view(str); });
|
|
|
|
auto rules = lines | std::views::take_while(not_empty)
|
|
| std::ranges::to<std::vector>();
|
|
auto updates = lines | std::views::drop_while(not_empty) | std::views::drop(1)
|
|
| std::ranges::to<std::vector>();
|
|
|
|
|
|
fmt::print("rules:\n");
|
|
std::ranges::for_each(rules, [](auto const& str) {
|
|
fmt::print("{}\n", str);
|
|
});
|
|
|
|
fmt::print("updates:\n");
|
|
std::ranges::for_each(updates, [](auto const& str) {
|
|
fmt::print("{}\n", str);
|
|
});
|
|
|
|
return {};
|
|
}
|
|
|
|
auto main([[maybe_unused]]int argc, [[maybe_unused]]char const* argv[]) -> int {
|
|
auto const res = entry({argv, static_cast<std::size_t>(argc)});
|
|
if (res) return 0;
|
|
fmt::print(stderr, "{}: {}\n", res.error().err.message(), res.error().msg);
|
|
return 1;
|
|
}
|