diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/2017/day9/aoc.cpp | 12 | ||||
-rw-r--r-- | src/2017/day9/aoc.h | 2 |
2 files changed, 9 insertions, 5 deletions
diff --git a/src/2017/day9/aoc.cpp b/src/2017/day9/aoc.cpp index 0b1cda6..9047aef 100644 --- a/src/2017/day9/aoc.cpp +++ b/src/2017/day9/aoc.cpp @@ -13,7 +13,7 @@ static void take(const char* p, std::stack<char>& gs, int* t) { } } -static bool is_valid(const char* p, std::stack<char>& g) { +static bool is_valid(const char* p, std::stack<char>& g, int* t) { if (g.empty()) { if (*p == '!') { g.push(*p); @@ -25,11 +25,14 @@ static bool is_valid(const char* p, std::stack<char>& g) { if (g.top() == '!') { g.pop(); } else { + *t += 1; if (*p == '>') { g.pop(); + *t -= 1; } if (*p == '!') { g.push(*p); + *t -= 1; } } } @@ -37,18 +40,19 @@ static bool is_valid(const char* p, std::stack<char>& g) { return g.empty(); } -int day9(line_view file) { +std::pair<int, int> day9(line_view file) { int t0{0}; + int t1{0}; std::stack<char> gs; std::stack<char> gv; const char* p = file.line; while (p < file.line + file.length) { - if (is_valid(p, gv)) { + if (is_valid(p, gv, &t1)) { take(p, gs, &t0); } p++; } - return t0; + return {t0, t1}; } } // namespace aoc2017 diff --git a/src/2017/day9/aoc.h b/src/2017/day9/aoc.h index 7fb26e7..0a8ac58 100644 --- a/src/2017/day9/aoc.h +++ b/src/2017/day9/aoc.h @@ -3,5 +3,5 @@ namespace aoc2017 { -int day9(line_view); +std::pair<int, int> day9(line_view); } |