aboutsummaryrefslogtreecommitdiff
path: root/src/2022/day22/aoc.cpp
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2023-01-04 09:41:00 +0800
committerkaiwu <kaiwu2004@gmail.com>2023-01-04 09:41:00 +0800
commit80794ea4f778ed984214585f11fd459fa736235f (patch)
treec268c41c40bfab9dec7f60cf612b19f4ebe68036 /src/2022/day22/aoc.cpp
parenteb059adcdb9796d6fec0b65c613755e1acfe43b6 (diff)
downloadadvent-of-code-80794ea4f778ed984214585f11fd459fa736235f.tar.gz
advent-of-code-80794ea4f778ed984214585f11fd459fa736235f.zip
2022 day22 cube travel
Diffstat (limited to 'src/2022/day22/aoc.cpp')
-rw-r--r--src/2022/day22/aoc.cpp73
1 files changed, 60 insertions, 13 deletions
diff --git a/src/2022/day22/aoc.cpp b/src/2022/day22/aoc.cpp
index a6e953c..101b604 100644
--- a/src/2022/day22/aoc.cpp
+++ b/src/2022/day22/aoc.cpp
@@ -13,11 +13,8 @@ struct person {
};
static int absolute_x(int x, const monkey_map& r) { return r.start + x; }
-
typedef int (*yf)(int, const std::vector<monkey_map>&);
-
int prev_y(int y, const std::vector<monkey_map>& ms) { return y == 0 ? ms.size() - 1 : y - 1; }
-
int next_y(int y, const std::vector<monkey_map>& ms) { return y == (int)ms.size() - 1 ? 0 : y + 1; }
int find_next(int x, int y, const std::vector<monkey_map>& ms, yf f) {
@@ -39,7 +36,7 @@ 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, '^');
+ // 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) == '.') {
@@ -53,7 +50,7 @@ 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');
+ // 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) == '.') {
@@ -67,7 +64,7 @@ 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, '<');
+ // 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 == '.') {
@@ -80,7 +77,7 @@ 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, '>');
+ // 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 == '.') {
@@ -114,6 +111,50 @@ void travel(person* p, const std::vector<monkey_map>& ms, const route& r) {
}
}
+char cube_get(person* p, cube_map* cm) {
+ int x = cm->x + p->x;
+ int y = cm->y + p->y;
+ auto& r = maps[y];
+ return *(r.line.line + x - r.start);
+}
+
+void cube_up(int s, person* p, cube_map** pcm) {
+
+}
+
+void cube_down(int s, person* p, cube_map** pcm) {
+
+}
+
+void cube_left(int s, person* p, cube_map** pcm) {
+
+}
+
+void cube_right(int s, person* p, cube_map** pcm) {
+
+}
+
+void travel_cube(person* p, cube_map** pcm, const route& r) {
+ if (r.is_step == false) {
+ p->f = r.ins.f;
+ } else {
+ switch (p->f) {
+ case up:
+ cube_up(r.ins.steps, p, pcm);
+ break;
+ case down:
+ cube_down(r.ins.steps, p, pcm);
+ break;
+ case left:
+ cube_left(r.ins.steps, p, pcm);
+ break;
+ case right:
+ cube_right(r.ins.steps, p, pcm);
+ break;
+ }
+ }
+}
+
void cube_sample(cube_map cubs[6]) {
// R2L
// D3U 1 R6L
@@ -319,16 +360,22 @@ std::pair<int64_t, int64_t> day22(line_view file) {
for (auto& r : routes) {
travel(&p, maps, r);
}
+ const monkey_map& r = maps[p.y];
+ int64_t n1 = (p.y + 1) * 1000 + 4 * (r.start + p.x + 1) + (int)p.f;
+
+ person pc{0, 0, right};
+ cube_map* cm = &cubs[0];
+ for (auto& r : routes) {
+ travel_cube(&pc, &cm, r);
+ }
+ int64_t n2 = (cm->y + p.y + 1) * 1000 + 4 * (cm->x + p.x + 1) + (int)p.f;
+ // char fs[] = {'>', 'v', '<', '^'};
+ // printf("person is at x[%d] y[%d] facing[%c]\n", r.start + p.x + 1, p.y + 1, fs[p.f]);
// for(auto&tm : tmaps) {
// tm.print();
// }
- // char fs[] = {'>', 'v', '<', '^'};
- 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};
+ return {n1, n2};
}
} // namespace aoc2022