Add solution for 2016 Day 6

This commit is contained in:
Thraix
2026-08-15 20:15:30 +02:00
parent bf12e141a6
commit 474e662ebd
2 changed files with 64 additions and 13 deletions
+16
View File
@@ -0,0 +1,16 @@
eedadn
drvtee
eandsr
raavrd
atevrs
tsrnev
sdttsa
rasrtv
nssdts
ntnada
svetve
tesnvt
vntsnd
vrdear
dvrsen
enarar
+48 -13
View File
@@ -2,30 +2,65 @@
namespace y2016::day06
{
REGISTER_DAY(2016, Day06, std::vector<int>, int);
REGISTER_DAY(2016, Day06, Array2D<char>, std::string);
REGISTER_TEST_EXAMPLE(2016, Day06, ExampleInput, 1, 0);
REGISTER_TEST(2016, Day06, Input, 1, 0);
REGISTER_TEST_EXAMPLE(2016, Day06, ExampleInput, 2, 0);
REGISTER_TEST(2016, Day06, Input, 2, 0);
REGISTER_TEST_EXAMPLE(2016, Day06, ExampleInput, 1, "easter");
REGISTER_TEST(2016, Day06, Input, 1, "xhnqpqql");
REGISTER_TEST_EXAMPLE(2016, Day06, ExampleInput, 2, "advent");
REGISTER_TEST(2016, Day06, Input, 2, "brhailro");
READ_INPUT(input)
{
std::vector<int> vec;
std::string str;
while (getline(input, str))
{
}
return vec;
return Input::ReadArray2D(input);
}
OUTPUT1(input)
{
return 0;
std::string result;
for (int x = 0; x < input.width; x++)
{
std::map<char, int> map;
for (int y = 0; y < input.height; y++)
{
map[input.Get(x, y)]++;
}
int max = 0;
char maxChar;
for (const auto& [c, count] : map)
{
if (count > max)
{
maxChar = c;
max = count;
}
}
result.push_back(maxChar);
}
return result;
}
OUTPUT2(input)
{
return 0;
std::string result;
for (int x = 0; x < input.width; x++)
{
std::map<char, int> map;
for (int y = 0; y < input.height; y++)
{
map[input.Get(x, y)]++;
}
int min = std::numeric_limits<int>::max();
char minChar;
for (const auto& [c, count] : map)
{
if (count < min)
{
minChar = c;
min = count;
}
}
result.push_back(minChar);
}
return result;
}
}