aocpp/2022/24.cpp

67 lines
1.3 KiB
C++
Raw Permalink Normal View History

2023-04-08 12:08:51 -07:00
#include <cstdint>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <boost/range/adaptor/indexed.hpp>
#include <doctest.h>
#include <aocpp/Coord.hpp>
#include <aocpp/Startup.hpp>
namespace {
struct World {
std::vector<aocpp::Coord> ups, downs, lefts, rights;
std::size_t height, width;
};
auto Parse(std::istream & in) -> World
{
auto result = World{};
auto y = std::size_t{0};
auto line = std::string{};
while (std::getline(in, line)) {
for (auto const [x,c] : boost::adaptors::index(line)) {
switch (c) {
case '>': result.rights.emplace_back(x-1,y-1); break;
case '<': result.lefts.emplace_back(x-1,y-1); break;
case '^': result.ups.emplace_back(x-1,y-1); break;
case 'v': result.downs.emplace_back(x-1,y-1); break;
}
}
++y;
}
result.height = y - 2;
result.width = line.size() - 2;
return result;
}
} // namespace
TEST_SUITE("2022-24 examples") {
TEST_CASE("example") {
std::istringstream in {
"#.#####\n"
"#.....#\n"
"#>....#\n"
"#.....#\n"
"#...v.#\n"
"#.....#\n"
"#####.#\n"
};
auto const world = Parse(in);
}
}
auto Main(std::istream & in, std::ostream & out) -> void
{
auto const input = Parse(in);
//out << "Part 1: " << Part1(in) << std::endl;
}