Add solution for 2016 Day 16
This commit is contained in:
@@ -0,0 +1 @@
|
||||
10000
|
||||
|
||||
+37
-10
@@ -2,30 +2,57 @@
|
||||
|
||||
namespace y2016::day16
|
||||
{
|
||||
REGISTER_DAY(2016, Day16, std::vector<int>, int);
|
||||
REGISTER_DAY(2016, Day16, std::string, std::string);
|
||||
|
||||
REGISTER_TEST_EXAMPLE(2016, Day16, ExampleInput, 1, 0);
|
||||
REGISTER_TEST(2016, Day16, Input, 1, 0);
|
||||
REGISTER_TEST_EXAMPLE(2016, Day16, ExampleInput, 2, 0);
|
||||
REGISTER_TEST(2016, Day16, Input, 2, 0);
|
||||
REGISTER_TEST_EXAMPLE(2016, Day16, ExampleInput, 1, "01100");
|
||||
REGISTER_TEST(2016, Day16, Input, 1, "10100011010101011");
|
||||
REGISTER_TEST(2016, Day16, Input, 2, "01010001101011001");
|
||||
|
||||
READ_INPUT(input)
|
||||
{
|
||||
std::vector<int> vec;
|
||||
std::string str;
|
||||
while (getline(input, str))
|
||||
getline(input, str);
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string ReverseFlip(const std::string& str)
|
||||
{
|
||||
std::string reverse;
|
||||
for (int i = str.size() - 1; i >= 0; i--)
|
||||
{
|
||||
reverse.push_back(str[i] == '1' ? '0' : '1');
|
||||
}
|
||||
return vec;
|
||||
return reverse;
|
||||
}
|
||||
|
||||
std::string Solve(std::string str, int length)
|
||||
{
|
||||
while (str.size() < length)
|
||||
{
|
||||
str = str + "0" + ReverseFlip(str);
|
||||
}
|
||||
str = str.substr(0, length);
|
||||
|
||||
std::string checksum;
|
||||
while (str.size() % 2 == 0)
|
||||
{
|
||||
for (int i = 0; i < str.size(); i += 2)
|
||||
{
|
||||
checksum.push_back(str[i] == str[i + 1] ? '1' : '0');
|
||||
}
|
||||
str = checksum;
|
||||
checksum.clear();
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
OUTPUT1(input)
|
||||
{
|
||||
return 0;
|
||||
return Solve(input, isExample ? 20 : 272);
|
||||
}
|
||||
|
||||
OUTPUT2(input)
|
||||
{
|
||||
return 0;
|
||||
return Solve(input, 35651584);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user