From 488b97ea6cda40576c4494e9e32c3b7566ee324a Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Thu, 11 Dec 2025 09:34:52 +0100 Subject: aoc 2025, day 11, part 1 --- 2025/src/day11.cpp | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 2025/src/day11.cpp (limited to '2025') diff --git a/2025/src/day11.cpp b/2025/src/day11.cpp new file mode 100644 index 0000000..47440f9 --- /dev/null +++ b/2025/src/day11.cpp @@ -0,0 +1,85 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +namespace { + +using Graph = map>; + +vector +split(const string& str, const string& delims) +{ + vector result; + + size_t start = str.find_first_not_of(delims); + while ( start != string::npos ) { + size_t end = str.find_first_of(delims, start); + + if ( end == string::npos ) { + // letzter Teil + result.push_back(str.substr(start)); + break; + } + + result.push_back(str.substr(start, end - start)); + + start = str.find_first_not_of(delims, end); + } + + return result; +} + +Graph +read_file(const filesystem::path& filename) +{ + ifstream file{ filename }; + + Graph graph; + for ( string line; getline(file, line); ) { + auto parts = split(line, ": "); + graph[parts[0]].insert(parts.begin() + 1, parts.end()); + } + return graph; +} + +void +part1(const Graph& graph) +{ + map cache; + + function dfs = [&](const string& src) { + if ( src == "out" ) { + return 1L; + } + + if ( cache.contains(src) ) { + return cache.at(src); + } + + long count = 0; + + for ( const auto& node: graph.at(src) ) { + count += dfs(node); + } + + return cache[src] = count; + }; + + cout << "Part 1: " << dfs("you") << '\n'; +} + +} // namespace + +int +main() +{ + auto graph = read_file("data/day11.txt"); + part1(graph); +} -- cgit v1.3