diff --git a/advent_of_code/2022/3/main.cpp b/advent_of_code/2022/3/main.cpp index aa77dbf..d27c703 100644 --- a/advent_of_code/2022/3/main.cpp +++ b/advent_of_code/2022/3/main.cpp @@ -28,8 +28,32 @@ int main(){ // } // } + map badges; + int group_counter = 0; while(getline(input_file, line)){ + set items; + for(char c : line){ + items.insert(c); + } + + for(char c : items){ + badges[c] += 1; + + if(badges[c] == 3){ + if(c >= 'a' && c <= 'z'){ + score += c - 'a' + 1; + } else{ + score += c - 'A' + 1 + 26; + } + } + } + if(group_counter == 2){ + group_counter = 0; + badges.clear(); + } else{ + group_counter++; + } } cout << "Score: " << score << endl;