aboutsummaryrefslogtreecommitdiff
path: root/src/2015/day8/aoc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/2015/day8/aoc.cpp')
-rw-r--r--src/2015/day8/aoc.cpp30
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