aboutsummaryrefslogtreecommitdiff
path: root/src/2022/day22/aoc.cpp
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2022-12-22 22:58:08 +0800
committerkaiwu <kaiwu2004@gmail.com>2022-12-22 22:58:08 +0800
commitb71a455726c04a5b12c771faef0d8a38e45de54b (patch)
tree7e3f554353bcd6a2f6ce48aa2ddc2c951df45732 /src/2022/day22/aoc.cpp
parent1e48202abdf34def6d88e85f3801abdbc8d642ad (diff)
downloadadvent-of-code-b71a455726c04a5b12c771faef0d8a38e45de54b.tar.gz
advent-of-code-b71a455726c04a5b12c771faef0d8a38e45de54b.zip
2022 day22 part1
Diffstat (limited to 'src/2022/day22/aoc.cpp')
-rw-r--r--src/2022/day22/aoc.cpp89
1 files changed, 16 insertions, 73 deletions
diff --git a/src/2022/day22/aoc.cpp b/src/2022/day22/aoc.cpp
index 3a0f4e2..305d5f2 100644
--- a/src/2022/day22/aoc.cpp
+++ b/src/2022/day22/aoc.cpp
@@ -15,9 +15,11 @@ int get_x(int x, const monkey_map& r0, const monkey_map& r1) {
int s0 = r0.start + r0.line.length;
int s1 = r1.start + r1.line.length;
- if (s0 < s1) {
+ if (s0 < s1 && r0.start + x >= r1.start) {
+ return r0.start + x - r1.start;
}
- if (s0 > s1) {
+ if (s0 > s1 && r0.start + x < s1) {
+ return r0.start + x - r1.start;
}
return x;
}
@@ -45,79 +47,20 @@ int find_first(int y, const std::vector<monkey_map>& ms) {
return n;
}
+int find_next(int y, const std::vector<monkey_map>& ms, facing f) {
+ int first = find_first(y, ms);
+ int last = find_last(y, ms);
+ if (f == down) {
+ return last == y ? first : y + 1;
+ }
+ if (f == up) {
+ return first = y ? last : y - 1;
+ }
+ return y;
+}
+
void go_up(int s, person* p, const std::vector<monkey_map>& ms) {
if (s > 0) {
- // const monkey_map& r = ms[p->y - 1];
- // const monkey_map& r0 = ms[p->y - 2];
- // int x = p->x - 1;
- // if (r0.start < r.start) {
- // if (r.start + x >= r0.start + (int)r0.line.length) { // wrap
- // auto n = p->y - 1;
- // while (ms[n].start == r.start && n < (int)ms.size())
- // n++;
- // const monkey_map& r1 = ms[n - 1];
- // char c = *(r1.line.line + x);
- // if (c == ' ') {
- // printf("brrrr < wrap %d %d\n", p->x - 1, p->y - 1);
- // return;
- // }
- // if (c == '.') {
- // p->y = n - 1;
- // go_up(s - 1, p, ms);
- // }
- // } else {
- // int x0 = r.start + x - r0.start;
- // char c = *(r0.line.line + x0);
- // if (c == ' ') {
- // printf("brrrr < no wrap %d %d\n", p->x - 1, p->y - 1);
- // return;
- // }
- // if (c == '.') {
- // p->y -= 1;
- // p->x = x0;
- // go_up(s - 1, p, ms);
- // }
- // }
- // }
- // if (r0.start == r.start) {
- // char c = *(r0.line.line + x);
- // if (c == ' ') {
- // printf("brrrr = %d %d\n", p->x - 1, p->y - 1);
- // return;
- // }
- // if (c == '.') {
- // p->y -= 1;
- // go_up(s - 1, p, ms);
- // }
- // }
- // if (r0.start > r.start) {
- // if (r.start + x < r0.start) {
- // auto n = p->y - 1;
- // while (ms[n].start == r.start && n < (int)ms.size())
- // n++;
- // const monkey_map& r1 = ms[n - 1];
- // char c = *(r1.line.line + x);
- // if (c == ' ') {
- // printf("brrrr > wrap %d %d\n", p->x - 1, p->y - 1);
- // return;
- // }
- // if (c == '.') {
- // p->y = n - 1;
- // go_up(s - 1, p, ms);
- // }
- // } else {
- // int x0 = r.start + x - r0.start;
- // char c = *(r0.line.line + x0);
- // if (c == ' ') {
- // printf("brrrr > no wrap %d %d\n", p->x - 1, p->y - 1);
- // }
- // if (c == '.') {
- // p->y -= 1;
- // p->x = x0;
- // go_up(s - 1, p, ms);
- // }
- // }
- // }
}
}