feat: complete AoC 2020-12-06

This commit is contained in:
Rekai Nyangadzayi Musuka 2020-12-06 00:00:05 -06:00
parent 8da4ced009
commit 227ebdc784
4 changed files with 2324 additions and 0 deletions

3
day_6/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/.idea
/cmake-build-debug
sample.txt

6
day_6/CMakeLists.txt Normal file
View File

@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.19)
project(day_6)
set(CMAKE_CXX_STANDARD 20)
add_executable(day_6 main.cpp)

2237
day_6/input.txt Normal file

File diff suppressed because it is too large Load Diff

78
day_6/main.cpp Normal file
View File

@ -0,0 +1,78 @@
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <variant>
void part1(std::ifstream &input) {
uint32_t count = 0;
std::string groupAnswers;
std::string line;
groupAnswers = "";
while(std::getline(input, line)) {
if (line.empty()) {
count += groupAnswers.length();
groupAnswers = "";
continue;
}
for (char c : line) {
if (groupAnswers.find_first_of(c) == std::variant_npos) {
groupAnswers += c;
}
}
}
// Account for last entry
count += groupAnswers.length();
std::cout << "[P1] Count: " << count << std::endl;
}
void part2(std::ifstream &input) {
std::unordered_map<char, uint32_t> map = {};
uint32_t count = 0;
uint32_t memberCount = 0;
std::string line;
while (std::getline(input, line)) {
if (line.empty()) {
for (std::pair<const char, uint32_t> record : map) {
if (record.second == memberCount) count++;
}
memberCount = 0;
map = {};
continue;
}
for (char c : line) {
uint32_t value = 0;
if (map.contains(c)) value = map.at(c);
map.insert_or_assign(c, value + 1);
}
memberCount++;
}
// Check for one missing?
for (std::pair<const char, uint32_t> record : map) {
if (record.second == memberCount) count++;
}
std::cout << "[P2] Count: " << count << std::endl;
}
int main() {
std::ifstream input { "../input.txt" };
part1(input);
input.clear();
input.seekg(0);
part2(input);
return 0;
}