aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/2020/day7/aoc.cpp20
-rw-r--r--src/2020/day7/aoc.h2
-rw-r--r--src/2020/day7/input17
3 files changed, 24 insertions, 5 deletions
diff --git a/src/2020/day7/aoc.cpp b/src/2020/day7/aoc.cpp
index 9ed0f99..caa2acf 100644
--- a/src/2020/day7/aoc.cpp
+++ b/src/2020/day7/aoc.cpp
@@ -16,20 +16,32 @@ bool find_color(color_bag* bag, line_view color) {
}
}
-int day7(line_view file, const char* color) {
+void count_color(color_bag* bag, int* total) {
+ for (auto& b : bag->bags) {
+ *total += b.second;
+ for (int i = 0; i < b.second; i++) {
+ count_color(b.first, total);
+ }
+ }
+}
+
+std::pair<int, int> day7(line_view file, const char* color) {
bag_regulations rs;
per_line(file, [&rs](line_view lv) {
rs.parse(lv);
return true;
});
- int total{0};
+ int t0{0};
for (auto& b : rs.regulations) {
if (!(b.second->color == color)) {
- total += int(find_color(b.second, color));
+ t0 += int(find_color(b.second, color));
}
}
- return total;
+ int t1{0};
+ count_color(rs.regulations[color], &t1);
+
+ return {t0, t1};
}
} // namespace aoc2020
diff --git a/src/2020/day7/aoc.h b/src/2020/day7/aoc.h
index 189237e..3ad7539 100644
--- a/src/2020/day7/aoc.h
+++ b/src/2020/day7/aoc.h
@@ -55,5 +55,5 @@ struct bag_regulations {
}
};
-int day7(line_view, const char*);
+std::pair<int, int> day7(line_view, const char*);
} // namespace aoc2020
diff --git a/src/2020/day7/input1 b/src/2020/day7/input1
new file mode 100644
index 0000000..2723ca0
--- /dev/null
+++ b/src/2020/day7/input1
@@ -0,0 +1,7 @@
+shiny gold bags contain 2 dark red bags.
+dark red bags contain 2 dark orange bags.
+dark orange bags contain 2 dark yellow bags.
+dark yellow bags contain 2 dark green bags.
+dark green bags contain 2 dark blue bags.
+dark blue bags contain 2 dark violet bags.
+dark violet bags contain no other bags.