diff options
-rw-r--r-- | src/2022/day5/aoc.h | 14 | ||||
-rw-r--r-- | test/test_2022.cpp | 2 |
2 files changed, 8 insertions, 8 deletions
diff --git a/src/2022/day5/aoc.h b/src/2022/day5/aoc.h index be1791e..1014bb7 100644 --- a/src/2022/day5/aoc.h +++ b/src/2022/day5/aoc.h @@ -1,5 +1,5 @@ #include "common.h" -#include <vector> +#include <stack> namespace aoc2022 { @@ -103,13 +103,13 @@ struct crate { } } if (mode == 2) { - std::vector<crate*> dx; - for (int x = 0; x < d[0]; x++) { - crate* c = take(d[1]); - dx.push_back(c); + std::stack<crate*> dx; + while(d[0]-- > 0) { + dx.push(take(d[1])); } - for (auto s = dx.size(); s > 0; s--) { - put(dx[s - 1], d[2]); + while(!dx.empty()) { + put(dx.top(), d[2]); + dx.pop(); } } } diff --git a/test/test_2022.cpp b/test/test_2022.cpp index 387c575..71cce9d 100644 --- a/test/test_2022.cpp +++ b/test/test_2022.cpp @@ -35,7 +35,7 @@ TEST_CASE("Camp Cleanup", "[2022]") { REQUIRE(823 == p.second); } -TEST_CASE("", "[2022]") { +TEST_CASE("Supply Stacks", "[2022]") { line_view lv = load_file("../src/2022/day5/input"); char message[10] = {0}; aoc2022::day5(lv, message, 1); |