#include #include #include #include #include using mod_table = std::vector >; mod_table read_input(const char* _input) { std::ifstream input(_input); if(!input) { std::cerr << "Failed to open file: " << _input << std::endl; std::terminate(); } mod_table output; std::string str; while(input) { if(!std::getline(input, str)) break; std::vector ln(str.size()); int i=0; for(const auto& chr : str) { switch(chr) { case '#': ln[i] = true; default: i++; break; } } output.push_back(std::move(ln)); str.clear(); } return output; } template inline std::size_t wrapping_index(const V& vec, std::size_t i) { return (i % vec.size()); } std::size_t count_slope(const mod_table& table, std::size_t stepx, std::size_t stepy) { std::size_t x=0; std::size_t r=0; for(std::size_t y=0;y(1, 1), std::tuple(3, 1), std::tuple(5, 1), std::tuple(7, 1), std::tuple(1, 2), }; std::size_t r=1; for(const auto& [x, y] : paths) { r*= count_slope(table, x, y); } #else auto r = count_slope(table, 3, 1); #endif std::cout << r << std::endl; return 0; }