Add solution for 2016 Day 3
This commit is contained in:
1 parent
d71df0c742
commit
fc76349588
3 files changed
+58
-11
No files matched your search
+32
-11
@@ -2,30 +2,51 @@
|
||||
|
||||
namespace y2016::day03
|
||||
{
|
||||
REGISTER_DAY(2016, Day03, std::vector<int>, int);
|
||||
REGISTER_DAY(2016, Day03, Array2D<int>, int);
|
||||
|
||||
REGISTER_TEST_EXAMPLE(2016, Day03, ExampleInput, 1, 0);
|
||||
REGISTER_TEST(2016, Day03, Input, 1, 0);
|
||||
REGISTER_TEST_EXAMPLE(2016, Day03, ExampleInput, 2, 0);
|
||||
REGISTER_TEST(2016, Day03, Input, 2, 0);
|
||||
REGISTER_TEST_EXAMPLE(2016, Day03, ExampleInput, 1, 2);
|
||||
REGISTER_TEST(2016, Day03, Input, 1, 983);
|
||||
REGISTER_TEST_EXAMPLE(2016, Day03, ExampleInput, 2, 2);
|
||||
REGISTER_TEST(2016, Day03, Input, 2, 1836);
|
||||
|
||||
READ_INPUT(input)
|
||||
{
|
||||
std::vector<int> vec;
|
||||
std::string str;
|
||||
while (getline(input, str))
|
||||
return Input::ReadIntsAsArray2D(input);
|
||||
}
|
||||
|
||||
bool IsValid(const std::array<int, 3>& triangle)
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
int length = triangle.at(i) + triangle.at((i + 1) % 3);
|
||||
if (length <= triangle.at((i + 2) % 3))
|
||||
return false;
|
||||
}
|
||||
return vec;
|
||||
return true;
|
||||
}
|
||||
|
||||
OUTPUT1(input)
|
||||
{
|
||||
return 0;
|
||||
int count = 0;
|
||||
for (int y = 0; y < input.height; y++)
|
||||
{
|
||||
if (IsValid({input.Get(0, y), input.Get(1, y), input.Get(2, y)}))
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
OUTPUT2(input)
|
||||
{
|
||||
return 0;
|
||||
int count = 0;
|
||||
for (int y = 0; y < input.height; y += 3)
|
||||
{
|
||||
for (int x = 0; x < 3; x++)
|
||||
{
|
||||
if (IsValid({input.Get(x, y), input.Get(x, y + 1), input.Get(x, y + 2)}))
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user