aoc24: add day16
This commit is contained in:
84
sol/24/day16.cpp
Normal file
84
sol/24/day16.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#include <vector>
|
||||
#include <ranges>
|
||||
#include <numeric>
|
||||
#include <memory>
|
||||
|
||||
#include "aoc.hpp"
|
||||
#include "aoc/utils.hpp"
|
||||
#include "fmt/format.h"
|
||||
#include "stb_image_write.h"
|
||||
|
||||
using namespace aoc::types;
|
||||
using namespace std::string_view_literals;
|
||||
|
||||
namespace rme {
|
||||
struct node;
|
||||
struct edge;
|
||||
|
||||
struct edge {
|
||||
u64 n;
|
||||
u32 a;
|
||||
u32 b;
|
||||
};
|
||||
|
||||
struct node {
|
||||
u64 id;
|
||||
edge n;
|
||||
edge s;
|
||||
edge e;
|
||||
edge w;
|
||||
};
|
||||
|
||||
class graph {
|
||||
public:
|
||||
graph(std::string const& maze_str) : m_start(0), m_exit(0) {
|
||||
auto const lines = maze_str | std::views::split("\n"sv)
|
||||
| std::views::transform([](auto const& str) { return std::string_view(std::begin(str), std::end(str)); })
|
||||
| std::views::filter([](auto const& str){ return !str.empty(); })
|
||||
| std::ranges::to<std::vector>();
|
||||
|
||||
for (usize i = 0; i < lines.size(); ++i) {
|
||||
auto const& str = lines[i];
|
||||
for (usize j = 0; j < str.size(); ++j) {
|
||||
auto const c = str[j];
|
||||
node n{};
|
||||
auto const id = u64((u64(i + 1) << 32) | (j + 1));
|
||||
if (c == '#' || c == '\n') continue;
|
||||
if (c == 'S') m_start = id;
|
||||
if (c == 'E') m_exit = id;
|
||||
n.id = id;
|
||||
}
|
||||
}
|
||||
// for (usize i = 0; i < maze_str.size(); ++i) {
|
||||
// auto const c = maze_str[i];
|
||||
// node n{};
|
||||
//
|
||||
// if (c == '\n') {
|
||||
// ++row;
|
||||
// col = 1;
|
||||
// }
|
||||
// auto const id = u64((u64(row) << 32) | col++);
|
||||
// if (c == '#' || c == '\n') continue;
|
||||
// if (c == 'S') m_start = id;
|
||||
// if (c == 'E') m_exit = id;
|
||||
//
|
||||
// n.id = id;
|
||||
// }
|
||||
}
|
||||
|
||||
private:
|
||||
u64 m_start;
|
||||
u64 m_exit;
|
||||
std::vector<node> m_nodes{};
|
||||
std::vector<edge> m_edges{};
|
||||
};
|
||||
}
|
||||
|
||||
auto aoc24::day16([[maybe_unused]]std::span<char const*> const& args) -> std::expected<void, aoc::error> {
|
||||
// auto res = aoc::read_text("./dat/24/ex/16.txt");
|
||||
auto res = aoc::read_text("./dat/24/re/16.txt");
|
||||
if (!res) return std::unexpected(res.error());
|
||||
auto const txt = *res;
|
||||
|
||||
return {};
|
||||
}
|
||||
Reference in New Issue
Block a user