From 474e662ebd60db7460f2a2b38845ba425cf7ab26 Mon Sep 17 00:00:00 2001 From: Thraix Date: Sat, 15 Aug 2026 20:15:30 +0200 Subject: [PATCH] Add solution for 2016 Day 6 --- res/2016/day06/test_input.txt | 16 +++++++++ src/2016/Day06.cpp | 61 +++++++++++++++++++++++++++-------- 2 files changed, 64 insertions(+), 13 deletions(-) diff --git a/res/2016/day06/test_input.txt b/res/2016/day06/test_input.txt index e69de29..32ba518 100644 --- a/res/2016/day06/test_input.txt +++ b/res/2016/day06/test_input.txt @@ -0,0 +1,16 @@ +eedadn +drvtee +eandsr +raavrd +atevrs +tsrnev +sdttsa +rasrtv +nssdts +ntnada +svetve +tesnvt +vntsnd +vrdear +dvrsen +enarar diff --git a/src/2016/Day06.cpp b/src/2016/Day06.cpp index 531e1d3..9d1dd90 100644 --- a/src/2016/Day06.cpp +++ b/src/2016/Day06.cpp @@ -2,30 +2,65 @@ namespace y2016::day06 { - REGISTER_DAY(2016, Day06, std::vector, int); + REGISTER_DAY(2016, Day06, Array2D, 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 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 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 map; + for (int y = 0; y < input.height; y++) + { + map[input.Get(x, y)]++; + } + int min = std::numeric_limits::max(); + char minChar; + for (const auto& [c, count] : map) + { + if (count < min) + { + minChar = c; + min = count; + } + } + result.push_back(minChar); + } + return result; } }