feat: complete part 2 of 2020-12-01 Advent of Code

This commit is contained in:
Rekai Nyangadzayi Musuka 2020-12-01 20:07:33 -06:00
parent a65015ed02
commit 204bab640a
1 changed files with 36 additions and 2 deletions

View File

@ -2,10 +2,17 @@
#include <fstream> #include <fstream>
#include <vector> #include <vector>
int part_1();
int part_2();
int main() { int main() {
part_1();
part_2();
}
int part_1() {
std::vector<int> vector; std::vector<int> vector;
std::ifstream input("../input.txt"); std::ifstream input("../input.txt");
std::string line; std::string line;
while(std::getline(input, line)) { while(std::getline(input, line)) {
@ -17,9 +24,36 @@ int main() {
for (int j : vector) { for (int j : vector) {
if (i + j == 2020) { if (i + j == 2020) {
std::cout << (i * j) << std::endl; std::cout << (i * j) << std::endl;
return 0;
} }
} }
} }
return 0; return 1;
} }
int part_2() {
std::vector<int> vector;
std::ifstream input("../input.txt");
std::string line;
while(std::getline(input, line)) {
int num = std::stoi(line);
vector.push_back(num);
}
for (int i : vector) {
for (int j : vector) {
for (int k : vector) {
if (i + j + k == 2020) {
std::cout << (i * j * k) << std::endl;
return 0;
}
}
}
}
return 1;
}