Add solution for 2016 Day 5
- Add Md5 algorithm to library
This commit is contained in:
+42
-12
@@ -2,30 +2,60 @@
|
||||
|
||||
namespace y2016::day05
|
||||
{
|
||||
REGISTER_DAY(2016, Day05, std::vector<int>, int);
|
||||
REGISTER_DAY(2016, Day05, std::string, std::string);
|
||||
|
||||
REGISTER_TEST_EXAMPLE(2016, Day05, ExampleInput, 1, 0);
|
||||
REGISTER_TEST(2016, Day05, Input, 1, 0);
|
||||
REGISTER_TEST_EXAMPLE(2016, Day05, ExampleInput, 2, 0);
|
||||
REGISTER_TEST(2016, Day05, Input, 2, 0);
|
||||
REGISTER_TEST(2016, Day05, Input, 1, "f97c354d");
|
||||
REGISTER_TEST(2016, Day05, Input, 2, "863dde27");
|
||||
|
||||
READ_INPUT(input)
|
||||
{
|
||||
std::vector<int> vec;
|
||||
std::string str;
|
||||
while (getline(input, str))
|
||||
{
|
||||
}
|
||||
return vec;
|
||||
getline(input, str);
|
||||
return str;
|
||||
}
|
||||
|
||||
OUTPUT1(input)
|
||||
{
|
||||
return 0;
|
||||
int i = 0;
|
||||
std::string result;
|
||||
while (true)
|
||||
{
|
||||
std::string str = input + std::to_string(i);
|
||||
std::string s = Md5::Hash(str);
|
||||
if (Helper::StartsWith(s, "00000"))
|
||||
{
|
||||
result.push_back(s[5]);
|
||||
if (result.size() == 8)
|
||||
return result;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
OUTPUT2(input)
|
||||
{
|
||||
return 0;
|
||||
int i = 0;
|
||||
std::string result{"XXXXXXXX"};
|
||||
int replacements = 0;
|
||||
for (int i = 0;; i++)
|
||||
{
|
||||
std::string str = input + std::to_string(i);
|
||||
std::string s = Md5::Hash(str);
|
||||
if (Helper::StartsWith(s, "00000"))
|
||||
{
|
||||
if (s[5] < '0' || s[5] > '7')
|
||||
continue;
|
||||
|
||||
if (result[s[5] - '0'] == 'X')
|
||||
{
|
||||
result[s[5] - '0'] = s[6];
|
||||
replacements++;
|
||||
}
|
||||
if (replacements == 8)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user