aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2022-05-10 10:08:52 +0800
committerkaiwu <kaiwu2004@gmail.com>2022-05-10 10:08:52 +0800
commit6a51123201c23693f87b6b69b9db73aed39af874 (patch)
treebdc68ecd1d00c349658712347fbebe7b2c4b538f /src
parente9c464934c764ef7971684e1785587fd18dca81d (diff)
downloadadvent-of-code-6a51123201c23693f87b6b69b9db73aed39af874.tar.gz
advent-of-code-6a51123201c23693f87b6b69b9db73aed39af874.zip
2017 day8 better logic
Diffstat (limited to 'src')
-rw-r--r--src/2017/day8/aoc.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/2017/day8/aoc.cpp b/src/2017/day8/aoc.cpp
index a5af770..b4a9004 100644
--- a/src/2017/day8/aoc.cpp
+++ b/src/2017/day8/aoc.cpp
@@ -42,16 +42,14 @@ line_view get_label(const char** pp) {
static int inc(int x, int i) { return x + i; }
static int dec(int x, int i) { return x - i; }
static bool condition_met(line_view cond, int x, int i) {
- if (cond.length > 1) {
- if (*cond.line == '!') {
- return x != i;
- }
- if (*cond.line == '=') {
- return x == i;
- }
- return (*cond.line == '>') ? x >= i : x <= i;
+ if (*cond.line == '=') {
+ return x == i;
+ }
+ if (*cond.line == '!') {
+ return x != i;
}
- return (*cond.line == '>') ? x > i : x < i;
+ bool bs[] = {x > i, x < i, x >= i, x <= i};
+ return bs[size_t(*cond.line == '<') + (cond.length & 2)];
}
typedef int (*op)(int, int);