Skip to content

Commit 70b30df

Browse files
committed
6
1 parent 080e408 commit 70b30df

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

Diff for: cpp/6.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "common.h"
2+
3+
namespace {
4+
long p(const auto &input, size_t m) {
5+
const auto &s = input[0];
6+
std::unordered_map<char, long> st;
7+
for (size_t i = 0; i < m - 1; ++i)
8+
st[s[i]] += 1;
9+
10+
for (size_t i = m - 1; i < s.size(); ++i) {
11+
st[s[i]] += 1;
12+
if (st.size() == m)
13+
return i + 1;
14+
st[s[i - m + 1]] -= 1;
15+
if (!st.at(s[i - m + 1])) {
16+
st.erase(s[i - m + 1]);
17+
}
18+
}
19+
return -1;
20+
}
21+
} // namespace
22+
23+
int main() {
24+
const auto &input = gb::advent2021::readIn();
25+
gb::advent2021::writeOut(std::to_string(p(input, 4)));
26+
gb::advent2021::writeOut(std::to_string(p(input, 14)));
27+
}

Diff for: cpp/meson.build

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ executable('5',
2222
'5.cpp',
2323
dependencies: [])
2424

25-
# executable('6',
26-
# '6.cpp',
27-
# dependencies: [])
25+
executable('6',
26+
'6.cpp',
27+
dependencies: [])
2828

2929
# executable('7',
3030
# '7.cpp',

0 commit comments

Comments
 (0)