aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/2015/day7/aoc.h15
-rw-r--r--src/common.h7
2 files changed, 14 insertions, 8 deletions
diff --git a/src/2015/day7/aoc.h b/src/2015/day7/aoc.h
index b03c3a8..e161166 100644
--- a/src/2015/day7/aoc.h
+++ b/src/2015/day7/aoc.h
@@ -66,6 +66,7 @@ struct cals {
}
result compute(line_view w) const noexcept {
+ // std::cout << "compute " << w << std::endl;
uint16_t x = 0;
if (is_value(w, &x)) {
return {result::c_value, x};
@@ -75,33 +76,33 @@ struct cals {
}
}
- std::function<result()> op_and(line_view x, line_view y) const noexcept {
+ std::function<result()> op_and(line_view& x, line_view& y) const noexcept {
return [&x, &y, this]() -> result { return compute(x).op_and(compute(y)); };
}
- std::function<result()> op_or(line_view x, line_view y) const noexcept {
+ std::function<result()> op_or(line_view& x, line_view& y) const noexcept {
return [&x, &y, this]() -> result { return compute(x).op_or(compute(y)); };
}
- std::function<result()> op_leftshift(line_view x, line_view y) const noexcept {
+ std::function<result()> op_leftshift(line_view& x, line_view& y) const noexcept {
return [&x, &y, this]() -> result { return compute(x).op_leftshift(compute(y)); };
}
- std::function<result()> op_rightshift(line_view x, line_view y) const noexcept {
+ std::function<result()> op_rightshift(line_view& x, line_view& y) const noexcept {
return [&x, &y, this]() -> result { return compute(x).op_rightshift(compute(y)); };
}
- std::function<result()> op_not(line_view x, line_view y) const noexcept {
+ std::function<result()> op_not(line_view& x, line_view& y) const noexcept {
return [&x, this]() -> result { return compute(x).op_not(); };
}
- std::function<result()> op_value(line_view x, line_view y) const noexcept {
+ std::function<result()> op_value(line_view& x, line_view& y) const noexcept {
return [&x, this]() -> result { return compute(x); };
}
std::function<result()> parse(line_view line, line_view* x, line_view* y, line_view* w) const noexcept {
static struct _ {
- std::function<result()> (cals::*op)(line_view, line_view) const noexcept;
+ std::function<result()> (cals::*op)(line_view&, line_view&) const noexcept;
const char* label;
} ops[] = {
{&cals::op_and, "AND"},
diff --git a/src/common.h b/src/common.h
index e9dd01c..7659322 100644
--- a/src/common.h
+++ b/src/common.h
@@ -27,9 +27,14 @@ struct line_view {
size_t i = 0;
size_t j = 0;
while (i < length && j < lv.length) {
- if (line[i++] < line[j++]) {
+ if (line[i] < lv.line[j]) {
return true;
}
+ if (line[i] > lv.line[j]) {
+ return false;
+ }
+ i++;
+ j++;
}
return j < lv.length;
}