aboutsummaryrefslogtreecommitdiff
path: root/src/2022/day22/aoc.cpp
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2023-01-03 15:17:09 +0800
committerkaiwu <kaiwu2004@gmail.com>2023-01-03 15:17:09 +0800
commitef494748151a72327300c2fc6d2e29e5cdd4281e (patch)
treec8bdd78651a9a96916d36db85fda37a1b8bbd17f /src/2022/day22/aoc.cpp
parent7bae157c7239069897c96814fad472207e1b19dc (diff)
downloadadvent-of-code-ef494748151a72327300c2fc6d2e29e5cdd4281e.tar.gz
advent-of-code-ef494748151a72327300c2fc6d2e29e5cdd4281e.zip
2022 day22 part1
Diffstat (limited to 'src/2022/day22/aoc.cpp')
-rw-r--r--src/2022/day22/aoc.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/2022/day22/aoc.cpp b/src/2022/day22/aoc.cpp
index ba3ff0d..bdb255f 100644
--- a/src/2022/day22/aoc.cpp
+++ b/src/2022/day22/aoc.cpp
@@ -45,10 +45,10 @@ void mark(int x, int y, char c) {
void go_up(int s, person* p, const std::vector<monkey_map>& ms) {
if (s > 0) {
int ax = absolute_x(p->x, ms[p->y]);
+ mark(ax, p->y, '^');
int y = find_next(p->x, p->y, ms, prev_y);
const monkey_map& r = ms[y];
if (*(r.line.line + ax - r.start) == '.') {
- mark(ax, p->y, '^');
p->y = y;
p->x = ax - r.start;
go_up(s - 1, p, ms);
@@ -59,10 +59,10 @@ void go_up(int s, person* p, const std::vector<monkey_map>& ms) {
void go_down(int s, person* p, const std::vector<monkey_map>& ms) {
if (s > 0) {
int ax = absolute_x(p->x, ms[p->y]);
+ mark(ax, p->y, 'v');
int y = find_next(p->x, p->y, ms, next_y);
const monkey_map& r = ms[y];
if (*(r.line.line + ax - r.start) == '.') {
- mark(ax, p->y, 'v');
p->y = y;
p->x = ax - r.start;
go_down(s - 1, p, ms);
@@ -73,10 +73,10 @@ void go_down(int s, person* p, const std::vector<monkey_map>& ms) {
void go_left(int s, person* p, const std::vector<monkey_map>& ms) {
if (s > 0) {
const monkey_map& m = ms[p->y];
+ mark(m.start + p->x, p->y, '<');
int x = p->x - 1 >= 0 ? p->x - 1 : m.line.length - 1;
char c = *(m.line.line + x);
if (c == '.') {
- mark(m.start + p->x, p->y, '<');
p->x = x;
go_left(s - 1, p, ms);
}
@@ -86,10 +86,10 @@ void go_left(int s, person* p, const std::vector<monkey_map>& ms) {
void go_right(int s, person* p, const std::vector<monkey_map>& ms) {
if (s > 0) {
const monkey_map& m = ms[p->y];
+ mark(m.start + p->x, p->y, '>');
int x = p->x + 1 < (int) m.line.length ? p->x + 1 : 0;
char c = *(m.line.line + x);
if (c == '.') {
- mark(m.start + p->x, p->y, '>');
p->x = x;
go_right(s - 1, p, ms);
}
@@ -97,12 +97,12 @@ void go_right(int s, person* p, const std::vector<monkey_map>& ms) {
}
void travel(person* p, const std::vector<monkey_map>& ms, const route& r) {
- char fs[] = {'>', 'v', '<', '^'};
+ // char fs[] = {'>', 'v', '<', '^'};
if (r.is_step == false) {
- printf("%c", fs[r.ins.f]);
+ // printf("%c", fs[r.ins.f]);
p->f = r.ins.f;
} else {
- printf("%d\n", r.ins.steps);
+ // printf("%d\n", r.ins.steps);
switch (p->f) {
case up:
go_up(r.ins.steps, p, ms);
@@ -149,13 +149,14 @@ std::pair<int64_t, int64_t> day22(line_view file) {
travel(&p, maps, r);
}
- for(auto&tm : tmaps) {
- tm.print();
- }
+ // for(auto&tm : tmaps) {
+ // tm.print();
+ // }
// char fs[] = {'>', 'v', '<', '^'};
- // printf("person is at x[%d] y[%d] facing[%c]\n", p.x + 1, p.y + 1, fs[p.f]);
- int64_t n1 = (p.y + 1) * 1000 + 4 * (p.x + 1) + (int) p.f;
+ const monkey_map& r = maps[p.y];
+ // printf("person is at x[%d] y[%d] facing[%c]\n", r.start + p.x + 1, p.y + 1, fs[p.f]);
+ int64_t n1 = (p.y + 1) * 1000 + 4 * (r.start + p.x + 1) + (int) p.f;
return {n1, 0};
}