Add solution for 2015 Day 18
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
.#.#.#
|
||||
...##.
|
||||
#....#
|
||||
..#...
|
||||
#.#..#
|
||||
####..
|
||||
|
||||
+96
-13
@@ -2,30 +2,113 @@
|
||||
|
||||
namespace y2015::day18
|
||||
{
|
||||
REGISTER_DAY(2015, Day18, std::vector<int>, int);
|
||||
REGISTER_DAY(2015, Day18, Array2D<char>, int);
|
||||
|
||||
REGISTER_TEST_EXAMPLE(2015, Day18, ExampleInput, 1, 0);
|
||||
REGISTER_TEST(2015, Day18, Input, 1, 0);
|
||||
REGISTER_TEST_EXAMPLE(2015, Day18, ExampleInput, 2, 0);
|
||||
REGISTER_TEST(2015, Day18, Input, 2, 0);
|
||||
REGISTER_TEST_EXAMPLE(2015, Day18, ExampleInput, 1, 4);
|
||||
REGISTER_TEST(2015, Day18, Input, 1, 814);
|
||||
REGISTER_TEST_EXAMPLE(2015, Day18, ExampleInput, 2, 7);
|
||||
REGISTER_TEST(2015, Day18, Input, 2, 924);
|
||||
|
||||
READ_INPUT(input)
|
||||
{
|
||||
std::vector<int> vec;
|
||||
std::string str;
|
||||
while (getline(input, str))
|
||||
{
|
||||
}
|
||||
return vec;
|
||||
return Input::ReadArray2D(input);
|
||||
}
|
||||
|
||||
OUTPUT1(input)
|
||||
{
|
||||
return 0;
|
||||
Array2D<char> array1 = input;
|
||||
Array2D<char> array2 = input;
|
||||
Array2D<char>* current = &array1;
|
||||
Array2D<char>* other = &array2;
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
current->Each(
|
||||
[&other](const Array2D<char>& array, Index2D index)
|
||||
{
|
||||
int neighbors = array.GetNeighbors('#', index.x, index.y, true);
|
||||
if (array[index] == '#')
|
||||
{
|
||||
if (neighbors < 2 || neighbors > 3)
|
||||
{
|
||||
(*other)[index] = '.';
|
||||
}
|
||||
else
|
||||
{
|
||||
(*other)[index] = '#';
|
||||
}
|
||||
}
|
||||
else if (array[index] == '.')
|
||||
{
|
||||
if (neighbors == 3)
|
||||
{
|
||||
(*other)[index] = '#';
|
||||
}
|
||||
else
|
||||
{
|
||||
(*other)[index] = '.';
|
||||
}
|
||||
}
|
||||
});
|
||||
std::swap(current, other);
|
||||
}
|
||||
|
||||
return current->Count('#');
|
||||
}
|
||||
|
||||
OUTPUT2(input)
|
||||
{
|
||||
return 0;
|
||||
Array2D<char> array1 = input;
|
||||
Array2D<char> array2 = input;
|
||||
Array2D<char>* current = &array1;
|
||||
Array2D<char>* other = &array2;
|
||||
array1[Index2D{0, 0}] = '#';
|
||||
array2[Index2D{0, 0}] = '#';
|
||||
array1[Index2D{0, array1.height - 1}] = '#';
|
||||
array2[Index2D{0, array1.height - 1}] = '#';
|
||||
array1[Index2D{array1.width - 1, 0}] = '#';
|
||||
array2[Index2D{array1.width - 1, 0}] = '#';
|
||||
array1[Index2D{array1.width - 1, array1.height - 1}] = '#';
|
||||
array2[Index2D{array1.width - 1, array1.height - 1}] = '#';
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
current->Each(
|
||||
[&other](const Array2D<char>& array, Index2D index)
|
||||
{
|
||||
if (index.x == 0 && index.y == 0)
|
||||
return;
|
||||
if (index.x == 0 && index.y == array.height - 1)
|
||||
return;
|
||||
if (index.x == array.width - 1 && index.y == 0)
|
||||
return;
|
||||
if (index.x == array.width - 1 && index.y == array.height - 1)
|
||||
return;
|
||||
int neighbors = array.GetNeighbors('#', index.x, index.y, true);
|
||||
if (array[index] == '#')
|
||||
{
|
||||
if (neighbors < 2 || neighbors > 3)
|
||||
{
|
||||
(*other)[index] = '.';
|
||||
}
|
||||
else
|
||||
{
|
||||
(*other)[index] = '#';
|
||||
}
|
||||
}
|
||||
else if (array[index] == '.')
|
||||
{
|
||||
if (neighbors == 3)
|
||||
{
|
||||
(*other)[index] = '#';
|
||||
}
|
||||
else
|
||||
{
|
||||
(*other)[index] = '.';
|
||||
}
|
||||
}
|
||||
});
|
||||
std::swap(current, other);
|
||||
}
|
||||
|
||||
return current->Count('#');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user