Skip to content

Commit

Permalink
day02
Browse files Browse the repository at this point in the history
  • Loading branch information
JellevanKraaij committed Dec 2, 2023
1 parent 7cb7f02 commit 20a5a9a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions day02/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,32 @@ int main(int argc, char **argv) {
}

string line;
int total = 0;
int total1 = 0;
int total2 = 0;
while (getline(inputFile, line)) {
bool valid = true;
gameLine game = parseLine(line);
map<string, int> maxColor = {{"red", 0}, {"green", 0}, {"blue", 0}};
for (auto &color : game.colors) {
for (auto &c : color) {
if (gameBag[c.first] < c.second) {
valid = false;
}
if (maxColor[c.first] < c.second) {
maxColor[c.first] = c.second;
}
}
}
if (valid) {
cout << "Game " << game.gameId << " is valid" << endl;
total += game.gameId;
total1 += game.gameId;
}
int power = 1;
for (auto &c : maxColor) {
power *= c.second;
}
total2 += power;
}
cout << "Total: " << total << endl;
cout << "Total1: " << total1 << endl;
cout << "Total2: " << total2 << endl;
}

0 comments on commit 20a5a9a

Please sign in to comment.