From c2f5d41ff9b21d7a4aac0bfb7c34bbb57a38c82b Mon Sep 17 00:00:00 2001 From: kaiwu Date: Wed, 15 Mar 2023 09:52:47 +0800 Subject: 2017 day22 --- src/2017/day22/aoc.cpp | 7 +++---- src/2017/day23/README.md | 15 +++++++++++++++ src/2017/day23/input | 32 ++++++++++++++++++++++++++++++++ test/test_2017.cpp | 8 ++++---- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/2017/day22/aoc.cpp b/src/2017/day22/aoc.cpp index 8adacb1..8a70bc8 100644 --- a/src/2017/day22/aoc.cpp +++ b/src/2017/day22/aoc.cpp @@ -102,8 +102,8 @@ vpos burst2(std::map& nodes, vpos p, int* c) { nodes.insert({{p.x, p.y}, v_weakened}); } else { if (s == v_weakened) { - it->second = v_infected; *c += 1; + it->second = v_infected; } if (s == v_infected) { @@ -141,10 +141,9 @@ static void part1(std::map nodes, int* c) { static void part2(std::map nodes, int* c) { vpos p{0, 0, f_up}; - for (int i = 0; i < 100; i++) { + for (int i = 0; i < 10000000; i++) { p = burst2(nodes, p, c); } - printf("%d\n", *c); } std::pair day22(line_view file) { @@ -163,7 +162,7 @@ std::pair day22(line_view file) { // for (auto& n : infected) { // printf("%d,%d\n", n.x, n.y); // } - return {t0, 0}; + return {t0, t1}; } } // namespace aoc2017 diff --git a/src/2017/day23/README.md b/src/2017/day23/README.md index e69de29..34f9caf 100644 --- a/src/2017/day23/README.md +++ b/src/2017/day23/README.md @@ -0,0 +1,15 @@ +--- Day 23: Coprocessor Conflagration --- +You decide to head directly to the CPU and fix the printer from there. As you get close, you find an experimental coprocessor doing so much work that the local programs are afraid it will halt and catch fire. This would cause serious issues for the rest of the computer, so you head in and see what you can do. + +The code it's running seems to be a variant of the kind you saw recently on that tablet. The general functionality seems very similar, but some of the instructions are different: + +set X Y sets register X to the value of Y. +sub X Y decreases register X by the value of Y. +mul X Y sets register X to the result of multiplying the value contained in register X by the value of Y. +jnz X Y jumps with an offset of the value of Y, but only if the value of X is not zero. (An offset of 2 skips the next instruction, an offset of -1 jumps to the previous instruction, and so on.) +Only the instructions listed above are used. The eight registers here, named a through h, all start at 0. + +The coprocessor is currently set to some kind of debug mode, which allows for testing, but prevents it from doing any meaningful work. + +If you run the program (your puzzle input), how many times is the mul instruction invoked? + diff --git a/src/2017/day23/input b/src/2017/day23/input index e69de29..8155688 100644 --- a/src/2017/day23/input +++ b/src/2017/day23/input @@ -0,0 +1,32 @@ +set b 67 +set c b +jnz a 2 +jnz 1 5 +mul b 100 +sub b -100000 +set c b +sub c -17000 +set f 1 +set d 2 +set e 2 +set g d +mul g e +sub g b +jnz g 2 +set f 0 +sub e -1 +set g e +sub g b +jnz g -8 +sub d -1 +set g d +sub g b +jnz g -13 +jnz f 2 +sub h -1 +set g b +sub g c +jnz g 2 +jnz 1 3 +sub b -17 +jnz 1 -23 diff --git a/test/test_2017.cpp b/test/test_2017.cpp index ab7c8cb..4e25464 100644 --- a/test/test_2017.cpp +++ b/test/test_2017.cpp @@ -211,14 +211,14 @@ TEST_CASE("Fractal Art", "[2017]") { TEST_CASE("Sporifica Virus", "[2017]") { - line_view lv = load_file("../src/2017/day22/input0"); + line_view lv = load_file("../src/2017/day22/input"); auto p = aoc2017::day22(lv); - // REQUIRE(5246 == p.first); - REQUIRE(0 == p.second); + REQUIRE(5246 == p.first); + REQUIRE(2512059 == p.second); } -TEST_CASE("", "[2017]") { +TEST_CASE("Coprocessor Conflagration", "[2017]") { line_view lv = load_file("../src/2017/day23/input"); auto p = aoc2017::day23(lv); REQUIRE(0 == p.first); -- cgit v1.2.3