diff options
author | kaiwu <kaiwu2004@gmail.com> | 2023-01-03 14:46:52 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2023-01-03 14:46:52 +0800 |
commit | 7bae157c7239069897c96814fad472207e1b19dc (patch) | |
tree | 983f2c81e4d81cd81e4dae853624a16f79a681aa /src/2022/day22/aoc.cpp | |
parent | 86c1a73437118e7c03280fbc190bb2b654fa5da6 (diff) | |
download | advent-of-code-7bae157c7239069897c96814fad472207e1b19dc.tar.gz advent-of-code-7bae157c7239069897c96814fad472207e1b19dc.zip |
2022 day22 part1 trace
Diffstat (limited to 'src/2022/day22/aoc.cpp')
-rw-r--r-- | src/2022/day22/aoc.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/2022/day22/aoc.cpp b/src/2022/day22/aoc.cpp index 6133492..ba3ff0d 100644 --- a/src/2022/day22/aoc.cpp +++ b/src/2022/day22/aoc.cpp @@ -3,6 +3,7 @@ namespace aoc2022 { std::vector<monkey_map> maps; +std::vector<trace_map> tmaps; std::vector<route> routes; struct person { @@ -36,12 +37,18 @@ int find_next(int x, int y, const std::vector<monkey_map>& ms, yf f) { } } +void mark(int x, int y, char c) { + auto& r = tmaps[y]; + *(r.p + x) = 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]); 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); @@ -55,6 +62,7 @@ void go_down(int s, person* p, const std::vector<monkey_map>& ms) { 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); @@ -68,6 +76,7 @@ void go_left(int s, person* p, const std::vector<monkey_map>& ms) { 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); } @@ -80,6 +89,7 @@ void go_right(int s, person* p, const std::vector<monkey_map>& ms) { 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); } @@ -87,9 +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', '<', '^'}; if (r.is_step == false) { + printf("%c", fs[r.ins.f]); p->f = r.ins.f; } else { + printf("%d\n", r.ins.steps); switch (p->f) { case up: go_up(r.ins.steps, p, ms); @@ -122,9 +135,9 @@ std::pair<int64_t, int64_t> day22(line_view file) { return true; }); - // for(auto&m : maps) { - // m.print(); - // } + for(auto&m : maps) { + tmaps.emplace_back(m); + } // facing f = right; // for(auto& r: routes) { @@ -135,9 +148,13 @@ std::pair<int64_t, int64_t> day22(line_view file) { for (auto& r : routes) { travel(&p, maps, r); } + + for(auto&tm : tmaps) { + tm.print(); + } - char fs[] = {'>', 'v', '<', '^'}; - printf("person is at x[%d] y[%d] facing[%c]\n", p.x, p.y, fs[p.f]); + // 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; return {n1, 0}; |