Add solution for 2016 Day 19
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
5
|
||||||
|
|||||||
+51
-13
@@ -2,30 +2,68 @@
|
|||||||
|
|
||||||
namespace y2016::day19
|
namespace y2016::day19
|
||||||
{
|
{
|
||||||
REGISTER_DAY(2016, Day19, std::vector<int>, int);
|
REGISTER_DAY(2016, Day19, int, int);
|
||||||
|
|
||||||
REGISTER_TEST_EXAMPLE(2016, Day19, ExampleInput, 1, 0);
|
REGISTER_TEST_EXAMPLE(2016, Day19, ExampleInput, 1, 3);
|
||||||
REGISTER_TEST(2016, Day19, Input, 1, 0);
|
REGISTER_TEST(2016, Day19, Input, 1, 1842613);
|
||||||
REGISTER_TEST_EXAMPLE(2016, Day19, ExampleInput, 2, 0);
|
REGISTER_TEST_EXAMPLE(2016, Day19, ExampleInput, 2, 2);
|
||||||
REGISTER_TEST(2016, Day19, Input, 2, 0);
|
REGISTER_TEST(2016, Day19, Input, 2, 1424135);
|
||||||
|
|
||||||
READ_INPUT(input)
|
READ_INPUT(input)
|
||||||
{
|
{
|
||||||
std::vector<int> vec;
|
int i;
|
||||||
std::string str;
|
input >> i;
|
||||||
while (getline(input, str))
|
return i;
|
||||||
{
|
|
||||||
}
|
|
||||||
return vec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OUTPUT1(input)
|
OUTPUT1(input)
|
||||||
{
|
{
|
||||||
return 0;
|
std::vector<int> elves(input, 0);
|
||||||
|
for (int i = 0; i < input; i++)
|
||||||
|
{
|
||||||
|
elves[i] = i + 1;
|
||||||
|
}
|
||||||
|
int offset = 0;
|
||||||
|
while (elves.size() > 1)
|
||||||
|
{
|
||||||
|
std::vector<int> newElves;
|
||||||
|
for (int i = offset; i < elves.size(); i += 2)
|
||||||
|
{
|
||||||
|
newElves.emplace_back(elves[i]);
|
||||||
|
}
|
||||||
|
offset = (offset + (elves.size() % 2)) % 2;
|
||||||
|
elves = newElves;
|
||||||
|
}
|
||||||
|
return elves[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
OUTPUT2(input)
|
OUTPUT2(input)
|
||||||
{
|
{
|
||||||
return 0;
|
std::deque<int> start;
|
||||||
|
std::deque<int> end;
|
||||||
|
for (int i = 0; i < input / 2; i++)
|
||||||
|
{
|
||||||
|
start.push_back(i + 1);
|
||||||
|
}
|
||||||
|
for (int i = input / 2; i < input; i++)
|
||||||
|
{
|
||||||
|
end.push_back(i + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!start.empty())
|
||||||
|
{
|
||||||
|
end.pop_front();
|
||||||
|
|
||||||
|
end.push_back(start.front());
|
||||||
|
start.pop_front();
|
||||||
|
|
||||||
|
if (end.size() - start.size() == 2)
|
||||||
|
{
|
||||||
|
start.push_back(end.front());
|
||||||
|
end.pop_front();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return end.front();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <deque>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
@@ -20,6 +21,9 @@
|
|||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
static std::ostream& operator<<(std::ostream& stream, const std::vector<Args...>& container);
|
static std::ostream& operator<<(std::ostream& stream, const std::vector<Args...>& container);
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
static std::ostream& operator<<(std::ostream& stream, const std::deque<Args...>& container);
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
static std::ostream& operator<<(std::ostream& stream, const std::set<Args...>& container);
|
static std::ostream& operator<<(std::ostream& stream, const std::set<Args...>& container);
|
||||||
|
|
||||||
@@ -564,6 +568,12 @@ static std::ostream& operator<<(std::ostream& stream, const std::vector<Args...>
|
|||||||
return Helper::Print(stream, container);
|
return Helper::Print(stream, container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
static std::ostream& operator<<(std::ostream& stream, const std::deque<Args...>& container)
|
||||||
|
{
|
||||||
|
return Helper::Print(stream, container);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
static std::ostream& operator<<(std::ostream& stream, const std::set<Args...>& container)
|
static std::ostream& operator<<(std::ostream& stream, const std::set<Args...>& container)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user