diff options
-rw-r--r-- | src/2016/day12/README.md | 7 | ||||
-rw-r--r-- | src/2016/day12/aoc.cpp | 14 | ||||
-rw-r--r-- | test/test_2016.cpp | 6 |
3 files changed, 19 insertions, 8 deletions
diff --git a/src/2016/day12/README.md b/src/2016/day12/README.md index f661fc5..b28f890 100644 --- a/src/2016/day12/README.md +++ b/src/2016/day12/README.md @@ -26,3 +26,10 @@ dec a The above code would set register a to 41, increase its value by 2, decrease its value by 1, and then skip the last dec a (because a is not zero, so the jnz a 2 skips it), leaving register a at 42. When you move past the last instruction, the program halts. After executing the assembunny code in your puzzle input, what value is left in register a? + +--- Part Two --- + +As you head down the fire escape to the monorail, you notice it didn't start; register c needs to be initialized to the position of the ignition key. + +If you instead initialize register c to be 1, what value is now left in register a? + diff --git a/src/2016/day12/aoc.cpp b/src/2016/day12/aoc.cpp index aac00ff..bd3a395 100644 --- a/src/2016/day12/aoc.cpp +++ b/src/2016/day12/aoc.cpp @@ -84,14 +84,14 @@ void jnz(size_t* i, const char* p) { void non(size_t* i, const char* p) { *i += 1; } -void exec(size_t i, const std::vector<instruction>& todos) { +size_t exec(size_t i, const std::vector<instruction>& todos) { if (i < todos.size()) { todo_f fs[5] = {cpy, inc, dec, jnz, non}; auto d = todos[i]; - std::cout << d.todo << std::endl; + // std::cout << d.todo << std::endl; fs[d.which()](&i, d.todo.line + 4); - exec(i, todos); } + return i; } std::pair<int64_t, int64_t> day12(line_view file) { @@ -100,7 +100,11 @@ std::pair<int64_t, int64_t> day12(line_view file) { todos.emplace_back(line_view{lv.line, lv.length - 1}); return true; }); - // exec(0, todos); - return {0, 0}; + size_t i = 0; + while (i < todos.size()) { + i = exec(i, todos); + } + + return {registers[0], 0}; } } // namespace aoc2016 diff --git a/test/test_2016.cpp b/test/test_2016.cpp index e42d817..b253f94 100644 --- a/test/test_2016.cpp +++ b/test/test_2016.cpp @@ -106,7 +106,7 @@ TEST_CASE("Balance Bots", "[2016]") { REQUIRE(55637 == p.second); } -TEST_CASE("", "[2016]") { +TEST_CASE("Radioisotope Thermoelectric Generators", "[2016]") { line_view lv = load_file("../src/2016/day11/input"); auto p = aoc2016::day11(lv); REQUIRE(0 == p.first); @@ -114,10 +114,10 @@ TEST_CASE("", "[2016]") { } -TEST_CASE("", "[2016]") { +TEST_CASE("Leonardo's Monorail", "[2016]") { line_view lv = load_file("../src/2016/day12/input"); auto p = aoc2016::day12(lv); - REQUIRE(0 == p.first); + REQUIRE(318077 == p.first); REQUIRE(0 == p.second); } |