#include #include #include #include int part_1() { std::unordered_map map; std::ifstream input("../input.txt"); std::string line; int i = 0; while (std::getline(input, line)) { std::pair pair {std::stoi(line), i}; map.insert(pair); i++; } for (std::pair pair : map) { int num = pair.first; int compliment = 2020 - num; if (map.contains(compliment)) { std::cout << (num * compliment) << std::endl; return 0; } } return 1; } int part_2() { std::unordered_map map; std::ifstream input("../input.txt"); std::string line; int i = 0; while (std::getline(input, line)) { std::pair pair {std::stoi(line), i}; map.insert(pair); i++; } for (std::pair first_pair : map) { int num = first_pair.first; int compliment = 2020 - num; // Still two other numbers we gotta find from here for (std::pair second_pair : map) { int second_num = second_pair.first; int second_compliment = compliment - second_num; if (map.contains(second_compliment)) { std::cout << (num * second_num * second_compliment) << std::endl; return 0; } } } return 1; } int main() { part_1(); part_2(); }