diff options
Diffstat (limited to 'src/2022/day22/aoc.cpp')
-rw-r--r-- | src/2022/day22/aoc.cpp | 89 |
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); - // } - // } - // } } } |