From 1a0715149dace9bf609e028f281f2f14a73e1a51 Mon Sep 17 00:00:00 2001 From: Thraix Date: Mon, 15 Dec 2025 20:54:45 +0100 Subject: [PATCH] Add solution for 2025 Day 12 --- res/2025/day12/test_input.txt | 33 ++++++++++++++++++++ src/2025/Day12.cpp | 59 +++++++++++++++++++++++++++++------ 2 files changed, 82 insertions(+), 10 deletions(-) create mode 100644 res/2025/day12/test_input.txt diff --git a/res/2025/day12/test_input.txt b/res/2025/day12/test_input.txt new file mode 100644 index 0000000..e5e1b3d --- /dev/null +++ b/res/2025/day12/test_input.txt @@ -0,0 +1,33 @@ +0: +### +##. +##. + +1: +### +##. +.## + +2: +.## +### +##. + +3: +##. +### +##. + +4: +### +#.. +### + +5: +### +.#. +### + +4x4: 0 0 0 0 2 0 +12x5: 1 0 1 0 2 2 +12x5: 1 0 1 0 3 2 diff --git a/src/2025/Day12.cpp b/src/2025/Day12.cpp index 95c3995..2a416fc 100644 --- a/src/2025/Day12.cpp +++ b/src/2025/Day12.cpp @@ -2,31 +2,70 @@ namespace y2025::day12 { - using InputType = std::vector; + struct Area + { + int width; + int height; + std::vector presents; + }; + + struct Input2 + { + std::vector> boxes; + std::vector areas; + }; + + using InputType = Input2; REGISTER_DAY(2025, Day12, InputType, int); - REGISTER_TEST_EXAMPLE(2025, Day12, ExampleInput, 1, 0); - REGISTER_TEST(2025, Day12, Input, 1, 0); + // REGISTER_TEST_EXAMPLE(2025, Day12, ExampleInput, 1, 2); + REGISTER_TEST(2025, Day12, Input, 1, 422); REGISTER_TEST_EXAMPLE(2025, Day12, ExampleInput, 2, 0); REGISTER_TEST(2025, Day12, Input, 2, 0); READ_INPUT(input) { - std::vector vec; + Input2 i; std::string str; while (std::getline(input, str)) { - std::stringstream ss{str}; - int n; - ss >> n; - vec.emplace_back(n); + if (str.empty()) + continue; + if (str[1] == ':') + { + i.boxes.emplace_back(Input::ReadArray2D(input)); + } + else + { + Area area; + std::stringstream ss{str}; + ss >> area.width >> "x" >> area.height >> ":"; + int n; + while (ss >> n) + { + area.presents.emplace_back(n); + } + i.areas.emplace_back(area); + } } - return vec; + return i; } OUTPUT1(input) { - return 0; + int total = 0; + for (auto& area : input.areas) + { + int a = area.width * area.height; + int sum = 0; + for (int i = 0; i < input.boxes.size(); i++) + { + sum += input.boxes[i].Count('#') * area.presents[i]; + } + if (sum <= a) + total++; + } + return total; } OUTPUT2(input)