-
Notifications
You must be signed in to change notification settings - Fork 0
/
AoC2022_06.cpp
49 lines (40 loc) · 1.34 KB
/
AoC2022_06.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
#include <assert.h>
#include <string>
#include <unordered_set>
#include <vector>
#include "../../aoc/aoc.hpp"
#include "../../aocd/aocd.hpp"
using namespace std;
using namespace aoc;
int solve(const string& buffer, const size_t size) {
for (int i : aoc::Range::range(size, buffer.size())) {
const string& sub = buffer.substr(i - size, size);
const unordered_set<char> s(sub.begin(), sub.end());
if (s.size() == size) {
return i;
}
};
throw "unsolvable";
}
int part1(const vector<string>& input) { return solve(input[0], 4); }
int part2(const vector<string>& input) { return solve(input[0], 14); }
// clang-format off
const vector<string> TEST1 = {"mjqjpqmgbljsphdztnvjfqwrcgsmlb"};
const vector<string> TEST2 = {"bvwbjplbgvbhsrlpgdmjqwftvncz"};
const vector<string> TEST3 = {"nppdvjthqldpwncqszvftbrmjlhg"};
const vector<string> TEST4 = {"nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg"};
const vector<string> TEST5 = {"zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw"};
// clang-format on
void samples() {
assert(part1(TEST1) == 7);
assert(part1(TEST2) == 5);
assert(part1(TEST3) == 6);
assert(part1(TEST4) == 10);
assert(part1(TEST5) == 11);
assert(part2(TEST1) == 19);
assert(part2(TEST2) == 23);
assert(part2(TEST3) == 23);
assert(part2(TEST4) == 29);
assert(part2(TEST5) == 26);
}
MAIN(2022, 6)