From 0464917d4de2143d3c464d54dc1c5590a541cbea Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Fri, 12 Dec 2025 13:42:16 +0100 Subject: aoc 2025, day 12, quick and dirty solution.. :/ --- 2025/src/day12.cpp | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 2025/src/day12.cpp (limited to '2025/src') diff --git a/2025/src/day12.cpp b/2025/src/day12.cpp new file mode 100644 index 0000000..d6f9277 --- /dev/null +++ b/2025/src/day12.cpp @@ -0,0 +1,92 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +namespace { + +using Region = tuple>; + +tuple, vector> +read_file(const filesystem::path& filename) +{ + ifstream file{ filename }; + vector lines; + + for ( string line; getline(file, line); ) { + lines.emplace_back(line); + } + + map areas; + + size_t idx = 0; + for ( ;; idx += 5 ) { + if ( lines.at(idx).at(1) != ':' ) { + break; + } + + const long num = lines.at(idx).at(0) - '0'; + + long count = 0; + for ( size_t j = idx + 1; j != idx + 4; ++j ) { + count += ranges::count(lines.at(j), '#'); + } + + areas[num] = count; + } + + vector regions; + for ( ; idx != lines.size(); ++idx ) { + static const regex rgx(R"(^(\d+)x(\d+):\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)$)"); + + smatch match; + if ( !regex_match(lines.at(idx), match, rgx) ) { + continue; + } + + regions.emplace_back( + stol(match[1]), // width + stol(match[2]), // height + array{ + stol(match[3]), + stol(match[4]), + stol(match[5]), + stol(match[6]), + stol(match[7]), + stol(match[8]) } // counts + ); + } + + return { areas, regions }; +} + +void +part1(const map& areas, const vector& regions) +{ + const auto result = ranges::count_if(regions, [&](const auto& region) { + const auto& [width, height, counts] = region; + + long required = 0; + for ( size_t i = 0; i != counts.size(); ++i ) { + required += counts.at(i) * areas.at(static_cast(i)); + } + return required < width * height; + }); + + cout << "Part 1: " << result << '\n'; +} + +} // namespace + +int +main() +{ + const auto [areas, regions] = read_file("data/day12.txt"); + part1(areas, regions); +} -- cgit v1.3