aboutsummaryrefslogtreecommitdiff
path: root/src/2017/day7/aoc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/2017/day7/aoc.cpp')
-rw-r--r--src/2017/day7/aoc.cpp24
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