diff --git a/day1/day1.cpp b/day1/day1.cpp index 0f9a082..d84ef63 100644 --- a/day1/day1.cpp +++ b/day1/day1.cpp @@ -2,7 +2,6 @@ #include #include #include -#include constexpr int TARGET_NUM = 2020; @@ -12,49 +11,49 @@ constexpr int TARGET_NUM = 2020; * @return std::set A set of the numbers in the input */ std::set read_input(const std::string &filename) { - std::set input; - std::string line; - std::ifstream file(filename); + std::set input; + std::string line; + std::ifstream file(filename); - while (std::getline(file, line)) { - int num = std::stoi(line); - input.insert(num); - } + while (std::getline(file, line)) { + int num = std::stoi(line); + input.insert(num); + } - return input; + return input; } int part1(const std::set &inputs) { - for (int num : inputs) { - int desired = TARGET_NUM - num; - if (inputs.find(desired) != inputs.end()) { - return desired * num; - } - } + for (int num : inputs) { + int desired = TARGET_NUM - num; + if (inputs.find(desired) != inputs.end()) { + return desired * num; + } + } - throw std::runtime_error("Does not contain solution"); + throw std::runtime_error("Does not contain solution"); } int part2(const std::set &inputs) { - for (int num : inputs) { - for (int num2 : inputs) { - int desired = TARGET_NUM - (num + num2); - if (inputs.find(desired) != inputs.end()) { - return desired * num2 * num; - } - } - } + for (int num : inputs) { + for (int num2 : inputs) { + int desired = TARGET_NUM - (num + num2); + if (inputs.find(desired) != inputs.end()) { + return desired * num2 * num; + } + } + } - throw std::runtime_error("Does not contain solution"); + throw std::runtime_error("Does not contain solution"); } int main(int argc, const char *argv[]) { - if (argc != 2) { - std::cerr << "./day1 " << std::endl; - return 1; - } + if (argc != 2) { + std::cerr << "./day1 " << std::endl; + return 1; + } - std::set inputs = read_input(argv[1]); - std::cout << part1(inputs) << std::endl; - std::cout << part2(inputs) << std::endl; + std::set inputs = read_input(argv[1]); + std::cout << part1(inputs) << std::endl; + std::cout << part2(inputs) << std::endl; }