-
Notifications
You must be signed in to change notification settings - Fork 9
/
day_07a.cpp
56 lines (55 loc) · 1.65 KB
/
day_07a.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <array>
#include <fstream>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
#include <ranges>
#include <string_view>
#include <algorithm>
int main(int argc, char* argv[]) {
std::string input = "../input/day_07_input";
if (argc > 1) {
input = argv[1];
}
std::string line;
std::fstream file(input);
int ports_with_tls_support = 0;
while(std::getline(file, line)) {
if (line.empty()) continue;
int bracket_count = 0;
bool supports = false;
if (line[0] == '[') bracket_count++;
for (std::size_t idx = 1; idx < line.size() - 2; idx++) {
if (line[idx] == '[') {
bracket_count++;
// supports = false;
} else if (line[idx] == ']') {
bracket_count--;
// supports = false;
} else if (line[idx] == line[idx+1]
&& line[idx-1] == line[idx+2]
&& line[idx-1] != line[idx]
&& std::all_of(
std::next(std::begin(line), idx - 1),
std::next(std::begin(line), idx + 2),
[](const auto c) {
return c != '[' && c !=']';
})){
if (bracket_count != 0) {
supports = false;
break;
} else {
// std::cout << line[idx-1] << line[idx]<<line[idx+1]<<line[idx+2]<< '\n';
supports = true;
}
}
}
if (supports) {
// std::cout << line << '\n';
ports_with_tls_support++;
}
}
std::cout << ports_with_tls_support << '\n';
return 0;
}