#include #include #include #include std::vector getDepths(const std::string &file_name) { std::ifstream file(file_name); std::vector result{}; int tmp = 0; std::string str; while (std::getline(file, str)) { std::stringstream ss(str); ss >> tmp; result.push_back(tmp); } return result; } int part1(const std::vector &input) { int result = 0; int tmp = input[0]; for (auto &depth : input) { if (depth > tmp) { result++; } tmp = depth; } return result; } int part2(const std::vector &input) { int result = 0; int tmp = input[0] + input[1] + input[2]; for (size_t i = 3; i < input.size(); i++) { auto window = input[i] + input[i - 1] + input[i - 2]; if (window > tmp) { result++; } tmp = window; } return result; } int main(int argc, char **argv) { if (argc < 2) { std::cerr << "You must provide input file!" << std::endl; return 1; } auto depths = getDepths(argv[1]); std::cout << "There are \033[91;1m" << part1(depths) << "\033[0m depth increases." << std::endl; std::cout << "There are \033[91;1m" << part2(depths) << "\033[0m window depth increases." << std::endl; return 0; }