#include #include #include #include #include #include #include #include "aoc.hpp" #include "aoc/utils.hpp" #include "fmt/format.h" #include "ctre.hpp" namespace cms { using vecn = std::vector; using matnxn = std::vector; // template // class mat { // class vec { // public: // vec(std::span const& data) : m_data(data) {} // // auto operator[](std::size_t i) const -> T const& { // return m_data[i]; // } // // private: // std::span m_data; // }; // // public: // mat() : m_data(), m_rows(0), m_cols(0) {} // // auto insert(std::size_t i, std::size_t j, T const& value) -> void { // if (i >= m_rows && j >= m_cols) { // std::vector tmp = m_data; // m_data.resize(i * j); // } // } // // auto operator[](std::size_t i) const -> mat::vec { // return vec({m_data[i * m_cols], m_data[i * m_cols + m_cols]}); // } // // private: // std::vector m_data; // std::size_t m_rows; // std::size_t m_cols; // }; // Permutations: std::vector xmas_patterns{ { {'X', 'M', 'A', 'S'}, {'X', 'M', 'A', 'S'}, {'X', 'M', 'A', 'S'}, {'X', 'M', 'A', 'S'}, }, { {'S', 'A', 'M', 'X'}, {'S', 'A', 'M', 'X'}, {'S', 'A', 'M', 'X'}, {'S', 'A', 'M', 'X'}, }, { {'X', 'X', 'X', 'X'}, {'M', 'M', 'M', 'M'}, {'A', 'A', 'A', 'A'}, {'S', 'S', 'S', 'S'}, }, { {'S', 'S', 'S', 'S'}, {'A', 'A', 'A', 'A'}, {'M', 'M', 'M', 'M'}, {'X', 'X', 'X', 'X'}, }, { {'X', 0, 0, 0}, { 0, 'M', 0, 0}, { 0, 0, 'A', 0}, { 0, 0, 0, 'S'}, }, { {'S', 0, 0, 0}, { 0, 'A', 0, 0}, { 0, 0, 'M', 0}, { 0, 0, 0, 'X'}, }, { { 0, 0, 0, 'S'}, { 0, 0, 'A', 0}, { 0, 'M', 0, 0}, {'X', 0, 0, 0}, }, { { 0, 0, 0, 'X'}, { 0, 0, 'M', 0}, { 0, 'A', 0, 0}, {'S', 0, 0, 0}, }, }; auto read_text_matnxn(std::string const& path) -> matnxn { std::ifstream strm{path}; if (!strm.is_open()) throw std::runtime_error(fmt::format("Failed to open file {}", path)); matnxn text{}; vecn cols{}; while (!strm.eof()) { auto const c = static_cast(strm.peek()); if (c == '\n') { text.emplace_back(std::move(cols)); } else { cols.push_back(c); } strm.get(); } return text; } } auto aoc24::day04([[maybe_unused]]std::span const& args) -> std::expected { auto source = cms::read_text_matnxn("./dat/24/ex/04.txt"); cms::vecn hpat{'X', 'M', 'A', 'S'}; // for (std::size_t i = 0; i < source.size(); ++i) { // auto const& cols = source[i]; // for (std::size_t j = 0; j < cols.size(); ++j) { // bool is_h_match = true; // for (std::size_t x = 0; x < hpat.size(); ++i) { // if (x + i >= cols.size()) { // is_h_match = false; // break; // } // if (hpat[x] != cols[x + i]) { // is_h_match = false; // break; // } // } // // // for (auto const& pattern : cms::xmas_patterns) { // // // for (std::size_t y = 0; y < pattern.size(); ++y) { // // // auto const& pcol = pattern[y]; // // // for (std::size_t x = 0; x < pcol.size(); ++x) { // // // if (y + i >= source.size() || x + j >= cols.size()) // // // break; // // // // // // if ( // // // } // // // } // // } // } // fmt::print("\n"); // } return {}; }