Line data Source code
1 : #include "PuzzleImpl.h"
2 :
3 : #include <libassert/assert.hpp>
4 :
5 : #include <algorithm>
6 : #include <iostream>
7 :
8 1 : template <> size_t part1<2015, 1>(std::string_view const input) {
9 1 : return 2 * std::ranges::count(input, '(') - input.size();
10 1 : }
11 :
12 1 : template <> size_t part2<2015, 1>(std::string_view const input) {
13 1 : int floor = 0;
14 1771 : for (size_t pos = 0; pos < input.size(); ++pos) {
15 1771 : floor += (input[pos] == '(') ? 1 : -1;
16 1771 : if (floor == -1)
17 1 : return pos + 1;
18 1771 : }
19 1 : UNREACHABLE();
20 0 : }
|