aboutsummaryrefslogtreecommitdiff
path: root/2016/src/day06.cpp
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2025-01-12 17:36:26 +0100
committerThomas Schmucker <ts@its1.de>2025-01-12 17:36:26 +0100
commitd396dc3221fcf893c885bd9a370b9a30f25b31dd (patch)
treef003b49ea2601a54926a2ef3de3b06f0f897dc37 /2016/src/day06.cpp
parenta8f11c0a8470c4e6b67e70219986712cd70d0de2 (diff)
downloadadvent-of-code-d396dc3221fcf893c885bd9a370b9a30f25b31dd.tar.gz
advent-of-code-d396dc3221fcf893c885bd9a370b9a30f25b31dd.tar.bz2
advent-of-code-d396dc3221fcf893c885bd9a370b9a30f25b31dd.zip
aoc 2016, days 4, 5, 6
Diffstat (limited to '2016/src/day06.cpp')
-rw-r--r--2016/src/day06.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/2016/src/day06.cpp b/2016/src/day06.cpp
new file mode 100644
index 0000000..5bd0f93
--- /dev/null
+++ b/2016/src/day06.cpp
@@ -0,0 +1,52 @@
1#include <fstream>
2#include <iostream>
3#include <map>
4#include <regex>
5#include <set>
6#include <sstream>
7#include <string>
8#include <tuple>
9#include <vector>
10
11using namespace std;
12
13vector<string>
14read_file(string_view filename)
15{
16 fstream input{ filename };
17
18 vector<string> lines;
19
20 for ( string line; getline(input, line); ) {
21 lines.emplace_back(line);
22 }
23
24 return lines;
25}
26
27void
28solve(const vector<string>& lines)
29{
30 string part1;
31 string part2;
32
33 for ( size_t col = 0; col != lines[0].length(); ++col ) {
34 map<char, size_t> counts;
35 for ( const auto& line: lines ) {
36 ++counts[line[col]];
37 }
38
39 part1 += max_element(counts.begin(), counts.end(), [](auto lhs, auto rhs) { return lhs.second < rhs.second; })->first;
40 part2 += min_element(counts.begin(), counts.end(), [](auto lhs, auto rhs) { return lhs.second < rhs.second; })->first;
41 }
42
43 cout << part1 << '\n'
44 << part2 << endl;
45}
46
47int
48main()
49{
50 auto lines = read_file("data/day06.txt");
51 solve(lines);
52}