#include "common.h" #include #include namespace aoc2022 { struct valve { line_view name; int rate = 0; std::vector 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 day16(line_view); }