aboutsummaryrefslogtreecommitdiff
path: root/src/2022/day16/aoc.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/2022/day16/aoc.h')
-rw-r--r--src/2022/day16/aoc.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/2022/day16/aoc.h b/src/2022/day16/aoc.h
index 82e0895..7678742 100644
--- a/src/2022/day16/aoc.h
+++ b/src/2022/day16/aoc.h
@@ -1,5 +1,54 @@
#include "common.h"
+#include <vector>
+#include <map>
namespace aoc2022 {
+
+struct valve {
+ line_view name;
+ int rate = 0;
+ std::vector<line_view> others;
+
+ friend bool operator<(const valve& v1, const valve& v2) {
+ return v1.rate > v2.rate;
+ }
+
+ void get_number(const char** pp, int* d) {
+ const char* p = *pp;
+ while(*p >= '0' && *p <= '9') {
+ *d = *d * 10 + *p - '0';
+ p++;
+ }
+ *pp = p;
+ }
+
+ bool isAZ(const char* p) {
+ return *p >= 'A' && *p <= 'Z';
+ }
+
+ bool is09(const char* p) {
+ return *p >= '0' && *p <= '9';
+ }
+
+ valve(line_view lv) {
+ const char *p = lv.line;
+ while (p < lv.line + lv.length) {
+ if (is09(p)) {
+ get_number(&p, &rate);
+ }
+ if (isAZ(p) && isAZ(p+1)) {
+ if (*(p+3) == 'h') {
+ name = line_view{p, 2};
+ }
+ else {
+ others.push_back({p, 2});
+ }
+ }
+ p++;
+ }
+ }
+};
+
+
std::pair<int, int> day16(line_view);
}