-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday06.cpp
39 lines (35 loc) · 1.05 KB
/
day06.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <bits/stdc++.h>
#include <range/v3/all.hpp>
using namespace std;
int main()
{
ifstream file("inputs/day06.txt");
string line;
set<int> answered;
map<char, int> answered_b;
int answer_a = 0, answer_b = 0, group_size = 0;
while (getline(file, line))
{
if (!line.length())
{
answer_a += answered.size();
answer_b += ranges::accumulate(ranges::view::values(answered_b), 0,
[&](int acc, int cnt) { return acc + (cnt == group_size); });
answered.clear();
answered_b.clear();
group_size = 0;
continue;
}
for (char c : line)
{
answered.insert(c);
answered_b[c]++;
}
group_size++;
}
answer_a += answered.size();
answer_b += ranges::accumulate(ranges::view::values(answered_b), 0,
[&](int acc, int cnt) { return acc + (cnt == group_size); });
cout << answer_a << endl;
cout << answer_b << endl;
}