aboutsummaryrefslogtreecommitdiff
path: root/src/2022/day7/aoc.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/2022/day7/aoc.h')
-rw-r--r--src/2022/day7/aoc.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/2022/day7/aoc.h b/src/2022/day7/aoc.h
index a0cc427..ffb381f 100644
--- a/src/2022/day7/aoc.h
+++ b/src/2022/day7/aoc.h
@@ -1,7 +1,52 @@
#include "common.h"
+#include <vector>
namespace aoc2022 {
+struct dir {
+ line_view name;
+ int size = 0;
+ dir* parent = nullptr;
+ std::vector<dir*> dirs = {};
+
+ int get_number(const char** pp) {
+ int d{0};
+ const char* p = *pp;
+ while(*p != ' ') {
+ d = 10 * d + *p - '0';
+ p++;
+ }
+ *pp = p + 1;
+ return d;
+ }
+
+ dir(line_view lv) {
+ const char* p = lv.line;
+ if (p[0] == '/') {
+ size = 0;
+ name = lv;
+ }
+ if (p[0] == 'd') {
+ size = 0;
+ name = line_view{p+4, lv.line + lv.length - 1};
+ }
+ else if (p[0] >= '0' && p[0] <= '9') {
+ size = get_number(&p);
+ name = line_view{p, lv.line + lv.length - 1};
+ }
+ }
+
+ int get_size() const noexcept {
+ int s{0};
+ s += size;
+ for (auto& d: dirs) {
+ s += d->get_size();
+ }
+ return s;
+ }
+
+};
+
std::pair<int,int> day7(line_view file);
}