diff options
author | kaiwu <kaiwu2004@gmail.com> | 2022-05-25 11:50:13 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2022-05-25 11:50:13 +0800 |
commit | 0b2be1ecc648f44785299c7d3c3c04ce06c45905 (patch) | |
tree | bd72e12001e1cf4c80849f446396111047aafedd /src | |
parent | 5b85fda638c61b6d8c24e9781ec45eb559563011 (diff) | |
download | advent-of-code-0b2be1ecc648f44785299c7d3c3c04ce06c45905.tar.gz advent-of-code-0b2be1ecc648f44785299c7d3c3c04ce06c45905.zip |
2017 day9
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); } |