#include "../aoc.h" #include #include #include int y2015_q01_p01(std::string instructions) { int floor = 0; for (const char &c : instructions) { floor += c == '(' ? 1 : -1; } return floor; } int y2015_q01_p02(std::string instructions) { int floor = 0; for (std::size_t i = 0; i < instructions.size(); i++) { floor += instructions[i] == '(' ? 1 : -1; if (floor == -1) return i + 1; } return -1; } std::vector splitstring(std::string input, char splitter) { std::stringstream splitterstream(input); std::string segment; std::vector splatstring; while (std::getline(splitterstream, segment, splitter)) { splatstring.push_back(segment); } return splatstring; } int y2015_q02_p01_instance(int l, int w, int h) { return std::min(l * w, std::min(l * h, h * w)) + 2 * l * w + 2 * l * h + 2 * w * h; } int y2015_q02_p01() { int sum = 0; std::string input; getline(std::cin, input); while (input != "-1") { std::vector split = splitstring(input, 'x'); sum += y2015_q02_p01_instance(std::stoi(split[0]), std::stoi(split[1]), std::stoi(split[2])); getline(std::cin, input); } return sum; } int y2015_q02_p02_instance(int l, int w, int h) { return std::min(2 * (l + w), std::min(2 * (l + h), 2 * (w + h))) + l * w * h; } int y2015_q02_p02() { int sum = 0; std::string input; getline(std::cin, input); while (input != "-1") { std::vector split = splitstring(input, 'x'); sum += y2015_q02_p02_instance(std::stoi(split[0]), std::stoi(split[1]), std::stoi(split[2])); getline(std::cin, input); } return sum; }