diff options
author | kaiwu <kaiwu2004@gmail.com> | 2022-03-18 14:33:33 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2022-03-18 14:33:33 +0800 |
commit | 056c57d1808e9f11eda435729deda8b6d279ce91 (patch) | |
tree | 4b7dae6db7c191ecc85dfd277f7fe6c8c4bc012e /src/2015/day8/aoc.cpp | |
parent | 96f4ab93a21e6e0fc7213b2b24757110f8146d71 (diff) | |
download | advent-of-code-056c57d1808e9f11eda435729deda8b6d279ce91.tar.gz advent-of-code-056c57d1808e9f11eda435729deda8b6d279ce91.zip |
day8 done
Diffstat (limited to 'src/2015/day8/aoc.cpp')
-rw-r--r-- | src/2015/day8/aoc.cpp | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/2015/day8/aoc.cpp b/src/2015/day8/aoc.cpp index feae5dc..be789d2 100644 --- a/src/2015/day8/aoc.cpp +++ b/src/2015/day8/aoc.cpp @@ -5,43 +5,51 @@ namespace aoc2015 { // \\ -> 1 // \" -> 1 // \xXX -> 1 -int count_day8(line_view lv) { - int total = 0; +std::pair<int, int> count_day8(line_view lv) { + int t1 = 0; + int t2 = 0; const char* p1 = lv.line; const char* p2 = lv.line + lv.length; const char* p = p1; while (p != p2) { if (*p != '\\' || p == p2 - 1) { - total += 1; + t1 += 1; + t2 += 1; p++; continue; } else { if (*(p + 1) == '\\' || *(p + 1) == '"') { - total += 1; + t1 += 1; + t2 += 4; p += 2; continue; } if (*(p + 1) == 'x') { - total += 1; + t1 += 1; + t2 += 5; p += 4; continue; } - total += 1; + t1 += 1; + t2 += 1; p++; } } - return total; + return {t1, t2}; } -int day8(line_view file) { +std::pair<int, int> day8(line_view file) { int t1 = 0; int t2 = 0; - per_line(file, [&t1, &t2](line_view lv) { + int t3 = 0; + per_line(file, [&t1, &t2, &t3](line_view lv) { t1 += lv.length - 1; - t2 += count_day8({lv.line + 1, lv.line + lv.length - 2}); + auto p = count_day8({lv.line + 1, lv.line + lv.length - 2}); + t2 += p.first; + t3 += p.second + 6; return true; }); - return t1 - t2; + return {t1 - t2, t3 - t1}; } } // namespace aoc2015 |