diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/2017/day7/aoc.cpp | 24 | ||||
-rw-r--r-- | src/2017/day7/aoc.h | 1 | ||||
-rw-r--r-- | src/2017/day7/input0 | 13 |
3 files changed, 38 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 diff --git a/src/2017/day7/aoc.h b/src/2017/day7/aoc.h index f3b9104..1a5a7d9 100644 --- a/src/2017/day7/aoc.h +++ b/src/2017/day7/aoc.h @@ -7,6 +7,7 @@ namespace aoc2017 { struct disc { line_view name; int weight; + int total = 0; std::vector<disc*> subs; const char* xp = nullptr; diff --git a/src/2017/day7/input0 b/src/2017/day7/input0 new file mode 100644 index 0000000..8a41324 --- /dev/null +++ b/src/2017/day7/input0 @@ -0,0 +1,13 @@ +pbga (66) +xhth (57) +ebii (61) +havc (66) +ktlj (57) +fwft (72) -> ktlj, cntj, xhth +qoyq (66) +padx (45) -> pbga, havc, qoyq +tknk (41) -> ugml, padx, fwft +jptl (61) +ugml (68) -> gyxo, ebii, jptl +gyxo (61) +cntj (57) |