-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathday_02a.cpp
27 lines (26 loc) · 888 Bytes
/
day_02a.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <fstream>
#include <iostream>
#include <regex>
#include <string>
int main(int argc, char * argv[]) {
std::string input = "../input/day_02_input";
if (argc > 1) {
input = argv[1];
}
std::ifstream file(input);
std::string line;
const std::regex pattern(R"(([0-9]+)x([0-9]+)x([0-9]+))");
int total = 0;
while(std::getline(file, line)) {
std::smatch match;
std::regex_search(line, match, pattern);
// Sample input
const auto area_1 = (std::stoi(match[1]) * std::stoi(match[2]));
const auto area_2 = (std::stoi(match[2]) * std::stoi(match[3]));
const auto area_3 = (std::stoi(match[3]) * std::stoi(match[1]));
const auto slack = std::min(std::min(area_1, area_2), area_3);
total += (area_1 + area_2 + area_3) * 2 + slack;
}
std::cout << total << '\n';
return 0;
}