diff options
author | kaiwu <kaiwu2004@gmail.com> | 2022-04-18 22:53:42 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2022-04-18 22:53:42 +0800 |
commit | 70f20b9317a11f443d01b4863969857173c63f14 (patch) | |
tree | 73ad7eda461a00a4e4293c867e650d31f26ffcb3 /src/2017/day7/aoc.cpp | |
parent | 0ef81936a3d4925db0d1e809a946153b33e65343 (diff) | |
download | advent-of-code-70f20b9317a11f443d01b4863969857173c63f14.tar.gz advent-of-code-70f20b9317a11f443d01b4863969857173c63f14.zip |
2017 day7
Diffstat (limited to 'src/2017/day7/aoc.cpp')
-rw-r--r-- | src/2017/day7/aoc.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/2017/day7/aoc.cpp b/src/2017/day7/aoc.cpp index 86e2e45..32a59ed 100644 --- a/src/2017/day7/aoc.cpp +++ b/src/2017/day7/aoc.cpp @@ -27,6 +27,27 @@ void depth(disc* d, int* dh) { } } +void weight(disc* d, int* w) { + int total{0}; + for (disc* x : d->subs) { + weight(x, &x->total); + total += x->total; + } + *w += d->weight + total; +} + +void print(disc* d, int depth) { + for (int i = 0; i < depth; i++) { + printf(" "); + } + std::cout << d->name << "(" << d->total << "," << d->weight << ")" << std::endl; + if (depth < 3) { + for (disc* x : d->subs) { + print(x, depth + 1); + } + } +} + void day7(line_view file, char name[]) { std::unordered_map<line_view, disc*> ds; per_line(file, [&ds](line_view lv) { @@ -52,6 +73,9 @@ void day7(line_view file, char name[]) { name[i++] = c; return true; }); + + weight(ds[x], &ds[x]->total); + // print(ds[x], 0); } } // namespace aoc2017 |