Add solution for 2016 Day 9

This commit is contained in:
Thraix
2026-08-16 11:56:04 +02:00
parent 3d9b19be4d
commit e5acfb8635
2 changed files with 55 additions and 10 deletions
+1
View File
@@ -0,0 +1 @@
X(8x2)(3x3)ABCY
+54 -10
View File
@@ -2,30 +2,74 @@
namespace y2016::day09
{
REGISTER_DAY(2016, Day09, std::vector<int>, int);
REGISTER_DAY(2016, Day09, std::string, uint64_t);
REGISTER_TEST_EXAMPLE(2016, Day09, ExampleInput, 1, 0);
REGISTER_TEST(2016, Day09, Input, 1, 0);
REGISTER_TEST_EXAMPLE(2016, Day09, ExampleInput, 2, 0);
REGISTER_TEST(2016, Day09, Input, 2, 0);
REGISTER_TEST_EXAMPLE(2016, Day09, ExampleInput, 1, 18);
REGISTER_TEST(2016, Day09, Input, 1, 99145);
REGISTER_TEST_EXAMPLE(2016, Day09, ExampleInput, 2, 20);
REGISTER_TEST(2016, Day09, Input, 2, 10943094568);
READ_INPUT(input)
{
std::vector<int> vec;
std::string str;
while (getline(input, str))
getline(input, str);
return str;
}
std::pair<int, int> GetMarker(const char* str)
{
char* end;
int length = std::strtol(str, &end, 10);
int repeat = std::strtol(end + 1, nullptr, 10);
return {length, repeat};
}
uint64_t GetLength(const char* str, size_t strLength)
{
size_t i = 0;
uint64_t count = 0;
while (i < strLength)
{
if (str[i] == '(')
{
size_t close = std::strstr(str + i, ")") - str;
auto [length, repeat] = GetMarker(str + i + 1);
count += GetLength(str + close + 1, length) * repeat;
i = close + 1 + length;
}
else
{
count++;
i++;
}
}
return vec;
return count;
}
OUTPUT1(input)
{
return 0;
uint64_t count = 0;
size_t i = 0;
while (i < input.size())
{
if (input[i] == '(')
{
size_t close = input.find(')', i);
auto [length, repeat] = GetMarker(input.c_str() + i + 1);
count += length * repeat;
i = close + 1 + length;
}
else
{
count++;
i++;
}
}
return count;
}
OUTPUT2(input)
{
return 0;
return GetLength(input.c_str(), input.size());
}
}