diff --git a/res/2016/day20/test_input.txt b/res/2016/day20/test_input.txt index e69de29..b5cde74 100644 --- a/res/2016/day20/test_input.txt +++ b/res/2016/day20/test_input.txt @@ -0,0 +1,3 @@ +5-8 +0-2 +4-7 diff --git a/src/2016/Day20.cpp b/src/2016/Day20.cpp index e6b4daa..ab0bc07 100644 --- a/src/2016/Day20.cpp +++ b/src/2016/Day20.cpp @@ -2,30 +2,60 @@ namespace y2016::day20 { - REGISTER_DAY(2016, Day20, std::vector, int); + using Input = std::vector>; + REGISTER_DAY(2016, Day20, Input, uint32_t); - REGISTER_TEST_EXAMPLE(2016, Day20, ExampleInput, 1, 0); - REGISTER_TEST(2016, Day20, Input, 1, 0); - REGISTER_TEST_EXAMPLE(2016, Day20, ExampleInput, 2, 0); - REGISTER_TEST(2016, Day20, Input, 2, 0); + REGISTER_TEST_EXAMPLE(2016, Day20, ExampleInput, 1, 3); + REGISTER_TEST(2016, Day20, Input, 1, 19449262); + REGISTER_TEST_EXAMPLE(2016, Day20, ExampleInput, 2, 2); + REGISTER_TEST(2016, Day20, Input, 2, 119); READ_INPUT(input) { - std::vector vec; + std::vector> vec; std::string str; while (getline(input, str)) { + std::pair pair; + std::stringstream ss{str}; + ss >> pair.first >> "-" >> pair.second; + vec.emplace_back(pair); } + std::sort(vec.begin(), vec.end()); return vec; } OUTPUT1(input) { + if (input.front().first != 0) + return 0; + + for (int i = 0; i < input.size(); i++) + { + if (input[i].second + 1 < input[i + 1].first) + return input[i].second + 1; + } return 0; } OUTPUT2(input) { - return 0; + uint64_t allowed = input.front().first; + uint64_t currentMax = input.front().second; + for (int i = 1; i < input.size(); i++) + { + if (currentMax < input[i].first - 1) + { + allowed += input[i].first - currentMax - 1; + currentMax = input[i].second; + } + else + { + currentMax = std::max(currentMax, input[i].second); + } + } + uint32_t max = isExample ? 9 : std::numeric_limits::max(); + allowed += max - currentMax; + return allowed; } }