diff options
Diffstat (limited to '2020')
| -rw-r--r-- | 2020/src/day02.cpp | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/2020/src/day02.cpp b/2020/src/day02.cpp index d7e28f1..cb70054 100644 --- a/2020/src/day02.cpp +++ b/2020/src/day02.cpp | |||
| @@ -30,9 +30,7 @@ part1(vector<tuple<long, long, char, string>>& data) | |||
| 30 | long sum = 0; | 30 | long sum = 0; |
| 31 | for ( const auto& [min, max, chr, password]: data ) { | 31 | for ( const auto& [min, max, chr, password]: data ) { |
| 32 | const auto amount = count(password.begin(), password.end(), chr); | 32 | const auto amount = count(password.begin(), password.end(), chr); |
| 33 | if ( min <= amount && amount <= max ) { | 33 | sum += static_cast<long>(min <= amount && amount <= max); |
| 34 | ++sum; | ||
| 35 | } | ||
| 36 | } | 34 | } |
| 37 | cout << sum << endl; | 35 | cout << sum << endl; |
| 38 | } | 36 | } |
| @@ -42,9 +40,7 @@ part2(vector<tuple<long, long, char, string>>& data) | |||
| 42 | { | 40 | { |
| 43 | long sum = 0; | 41 | long sum = 0; |
| 44 | for ( const auto& [min, max, chr, password]: data ) { | 42 | for ( const auto& [min, max, chr, password]: data ) { |
| 45 | if ( (password[size_t(min - 1)] == chr) ^ (password[size_t(max - 1)] == chr) ) { | 43 | sum += ((password[size_t(min - 1)] == chr) ^ (password[size_t(max - 1)] == chr)); |
| 46 | ++sum; | ||
| 47 | } | ||
| 48 | } | 44 | } |
| 49 | cout << sum << endl; | 45 | cout << sum << endl; |
| 50 | } | 46 | } |
