aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/2022/day9/aoc.cpp10
-rw-r--r--test/test_2022.cpp8
2 files changed, 12 insertions, 6 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};
}
}
diff --git a/test/test_2022.cpp b/test/test_2022.cpp
index 5b78db4..570aa55 100644
--- a/test/test_2022.cpp
+++ b/test/test_2022.cpp
@@ -69,9 +69,9 @@ TEST_CASE("Treetop Tree House", "[2022]") {
REQUIRE(519064 == p.second);
}
-TEST_CASE("", "[2022]") {
- line_view lv = load_file("../src/2022/day9/input1");
+TEST_CASE("Rope Bridge", "[2022]") {
+ line_view lv = load_file("../src/2022/day9/input");
auto p = aoc2022::day9(lv);
- // REQUIRE(6212 == p.first);
- REQUIRE(0 == p.second);
+ REQUIRE(6212 == p.first);
+ REQUIRE(2522 == p.second);
}