diff options
author | kaiwu <kaiwu2004@gmail.com> | 2023-02-06 14:46:22 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2023-02-06 14:46:22 +0800 |
commit | 99b5cc53a9b1e8860fc8ffdc0a91398513a1fc5a (patch) | |
tree | 5b541777050298c3a3af2934b8c7110600f23ad4 | |
parent | a8ba24a058c7026491e212d25d806a7359c33176 (diff) | |
download | advent-of-code-99b5cc53a9b1e8860fc8ffdc0a91398513a1fc5a.tar.gz advent-of-code-99b5cc53a9b1e8860fc8ffdc0a91398513a1fc5a.zip |
2016 day25
-rw-r--r-- | src/2016/day23/aoc.cpp | 34 | ||||
-rw-r--r-- | src/2016/day23/aoc.h | 1 | ||||
-rw-r--r-- | src/2016/day23/input25 | 30 | ||||
-rw-r--r-- | src/2016/day25/aoc.cpp | 2 | ||||
-rw-r--r-- | src/2016/day25/aoc.h | 2 | ||||
-rw-r--r-- | test/test_2016.cpp | 8 |
6 files changed, 69 insertions, 8 deletions
diff --git a/src/2016/day23/aoc.cpp b/src/2016/day23/aoc.cpp index 2a73886..a3b9b74 100644 --- a/src/2016/day23/aoc.cpp +++ b/src/2016/day23/aoc.cpp @@ -3,6 +3,7 @@ namespace aoc2016 { static int registers[4] = {7, 0, 0, 0}; +static size_t clock_signal = 0; static int& get(int i) { return registers[i]; } // c = a,b,c,d @@ -29,10 +30,12 @@ struct instruction23 { return toggle_is_odd ? 0 : 3; case 't': return toggle_is_odd ? 1 : 4; + case 'o': + return toggle_is_odd ? 1 : 5; default: break; } - return 5; + return 6; } }; @@ -77,6 +80,19 @@ static void dec(size_t* i, const char* p, const std::vector<instruction23>& todo *i += 1; } +static void out(size_t* i, const char* p, const std::vector<instruction23>& todos) { + + if (get(*p) == static_cast<int>(clock_signal & 1)) { + *i += 1; + clock_signal += 1; + } + else { + printf("%zu\n", clock_signal); + // printf("%d %d %d %d\n", get('a'), get('b'), get('c'), get('d')); + *i = UINT64_MAX; + } +} + static void jnz(size_t* i, const char* p, const std::vector<instruction23>& todos) { int d{0}; bool condition = false; @@ -114,7 +130,7 @@ static void tgl(size_t* i, const char* p, const std::vector<instruction23>& todo static void non(size_t* i, const char* p, const std::vector<instruction23>&) { *i += 1; } static size_t exec(size_t i, const std::vector<instruction23>& todos) { - todo_f fs[6] = {cpy, inc, dec, jnz, tgl, non}; + todo_f fs[7] = {cpy, inc, dec, jnz, tgl, out, non}; // const char *ds[6] = {"cpy", "inc", "dec", "jnz", "tgl", "non"}; auto d = todos[i]; auto x = d.which(); @@ -141,4 +157,18 @@ std::pair<int64_t, int64_t> day23(line_view file) { return {get('a'), 0}; } + +std::pair<int64_t, int64_t> day25(line_view file) { + for (int i = 0; i < 10000; i++) { + printf("%d ", i); + get('a') = i; + get('b') = 0; + get('c') = 0; + get('d') = 0; + clock_signal = 0; + day23(file); + } + + return {0, 0}; +} } // namespace aoc2016 diff --git a/src/2016/day23/aoc.h b/src/2016/day23/aoc.h index 2621f71..f39f215 100644 --- a/src/2016/day23/aoc.h +++ b/src/2016/day23/aoc.h @@ -4,4 +4,5 @@ namespace aoc2016 { std::pair<int64_t, int64_t> day23(line_view); +std::pair<int64_t, int64_t> day25(line_view); } diff --git a/src/2016/day23/input25 b/src/2016/day23/input25 new file mode 100644 index 0000000..3907038 --- /dev/null +++ b/src/2016/day23/input25 @@ -0,0 +1,30 @@ +cpy a d +cpy 11 c +cpy 231 b +inc d +dec b +jnz b -2 +dec c +jnz c -5 +cpy d a +jnz 0 0 +cpy a b +cpy 0 a +cpy 2 c +jnz b 2 +jnz 1 6 +dec b +dec c +jnz c -4 +inc a +jnz 1 -7 +cpy 2 b +jnz c 2 +jnz 1 4 +dec b +dec c +jnz 1 -4 +jnz 0 0 +out b +jnz a -19 +jnz 1 -21 diff --git a/src/2016/day25/aoc.cpp b/src/2016/day25/aoc.cpp index 7932389..8252b64 100644 --- a/src/2016/day25/aoc.cpp +++ b/src/2016/day25/aoc.cpp @@ -2,5 +2,5 @@ namespace aoc2016 { -std::pair<int64_t, int64_t> day25(line_view) { return {0, 0}; } +// std::pair<int64_t, int64_t> day25(line_view) { return {0, 0}; } } // namespace aoc2016 diff --git a/src/2016/day25/aoc.h b/src/2016/day25/aoc.h index e4b388f..f891d34 100644 --- a/src/2016/day25/aoc.h +++ b/src/2016/day25/aoc.h @@ -3,5 +3,5 @@ #include <vector> namespace aoc2016 { -std::pair<int64_t, int64_t> day25(line_view); +// std::pair<int64_t, int64_t> day25(line_view); } diff --git a/test/test_2016.cpp b/test/test_2016.cpp index 31320d6..51def48 100644 --- a/test/test_2016.cpp +++ b/test/test_2016.cpp @@ -221,8 +221,8 @@ TEST_CASE("Air Duct Spelunking", "[2016]") { TEST_CASE("Clock Signal", "[2016]") { - line_view lv = load_file("../src/2016/day25/input"); - auto p = aoc2016::day25(lv); - REQUIRE(0 == p.first); - REQUIRE(0 == p.second); + // line_view lv = load_file("../src/2016/day23/input25"); + // auto p = aoc2016::day25(lv); + // REQUIRE(0 == p.first); + // REQUIRE(0 == p.second); } |