aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2023-01-20 21:32:03 +0800
committerkaiwu <kaiwu2004@gmail.com>2023-01-20 21:32:03 +0800
commit7f9d12aec6e9bb37ad8f02550f24406827c4c691 (patch)
treeeb64b4aac33407dac782fffb6b439cea9b06d16c /src
parentd4206dc7bb5d7fb28cf874822bc4bcc10eafd880 (diff)
downloadadvent-of-code-7f9d12aec6e9bb37ad8f02550f24406827c4c691.tar.gz
advent-of-code-7f9d12aec6e9bb37ad8f02550f24406827c4c691.zip
2016 day12
Diffstat (limited to 'src')
-rw-r--r--src/2016/day12/README.md7
-rw-r--r--src/2016/day12/aoc.cpp14
2 files changed, 16 insertions, 5 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