#include #include #include #include #include std::vector read_input_file() { std::ifstream file("input"); std::vector data; std::string line; while(std::getline(file, line)) data.push_back(line); return data; } int count_trees(const std::vector &map, const std::pair &slope){ int trees = 0; int x = slope.first; int y = slope.second; int w = map[0].size(); int h = map.size(); while(y < h) { if(map[y][x%w] == '#') trees++; x += slope.first; y += slope.second; } return trees; } int solve_a(const std::vector &map) { return count_trees(map, {3, 1}); } long solve_b(const std::vector &map) { std::vector> slopes {{1, 1}, {3, 1}, {5, 1}, {7, 1}, {1, 2}}; long result = 1; for(auto& slope: slopes) result *= count_trees(map, slope); return result; } int main() { auto data = read_input_file(); std::cout << solve_a(data) << std::endl; std::cout << solve_b(data) << std::endl; return 0; }