#include "common.h" namespace aoc2022 { struct apair { int first[2] = {0}; int second[2] = {0}; void get_number(int* d, int i, const char* p) { *(d + i) = *(d + i) * 10 + *p - '0'; } void load(line_view lv) { int* d = first; int i{0}; const char* p0 = lv.line; while (p0 < lv.line + lv.length) { if (*p0 >= '0' && *p0 <= '9') { get_number(d, i, p0); } else { if (*p0 == ',') { d = second; i = 0; } if (*p0 == '-') { i += 1; } } p0++; } } bool covered() const noexcept { bool b1 = first[0] <= second[0] && first[1] >= second[1]; bool b2 = second[0] <= first[0] && second[1] >= first[1]; return b1 || b2; } bool overlap() const noexcept { bool b1 = second[0] >= first[0] && second[0] <= first[1]; bool b2 = second[1] >= first[0] && second[1] <= first[1]; bool b3 = first[0] >= second[0] && first[0] <= second[1]; bool b4 = first[1] >= second[0] && first[1] <= second[1]; return covered() || b1 || b2 || b3 || b4; } }; std::pair day4(line_view file); }