diff options
author | kaiwu <kaiwu2004@gmail.com> | 2022-12-09 20:56:13 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2022-12-09 20:56:13 +0800 |
commit | b6f21bfd0261d9a286d51524a38f9d1a389b5f22 (patch) | |
tree | 6d0876388d61f7245b24a92565f191b34e8f80fa /src | |
parent | 4e11ee3c519376954ca3fc69067e14b28723f234 (diff) | |
download | advent-of-code-b6f21bfd0261d9a286d51524a38f9d1a389b5f22.tar.gz advent-of-code-b6f21bfd0261d9a286d51524a38f9d1a389b5f22.zip |
2022 day9
Diffstat (limited to 'src')
-rw-r--r-- | src/2022/day9/aoc.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/2022/day9/aoc.cpp b/src/2022/day9/aoc.cpp index 2748141..94e5a01 100644 --- a/src/2022/day9/aoc.cpp +++ b/src/2022/day9/aoc.cpp @@ -101,7 +101,13 @@ struct arena { void follow(Co& t, Co& h) { int dy = h.y - t.y; int dx = h.x - t.x; - printf("(%d,%d) -> (%d,%d) %d %d\n", t.x, t.y, h.x, h.y, dx, dy); + // printf("(%d,%d) -> (%d,%d) %d %d\n", t.x, t.y, h.x, h.y, dx, dy); + if (std::abs(dy) == 2 && std::abs(dx) == 2) { + t.x += dx / 2; + t.y += dy / 2; + return; + } + if (dy == 2) { t.y += 1; t.x += dx; @@ -183,7 +189,7 @@ std::pair<int,int> day9(line_view file) { an.reset(); an.travel_tails(ms); int m2 = an.moves(); - return {m1, m2}; + return {m1, m2 + 1}; } } |