diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-12-25 13:29:16 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-12-25 13:29:16 +0100 |
commit | 8f688120afe73ec3b25d31294b5886f5651bde2e (patch) | |
tree | 5381345f0929f52077387ef192789a0b994eb44d | |
parent | 11269ed8c1be4af3b0bb8c355257481215b7dc9b (diff) | |
download | adventofcode2017-8f688120afe73ec3b25d31294b5886f5651bde2e.tar.gz adventofcode2017-8f688120afe73ec3b25d31294b5886f5651bde2e.tar.xz adventofcode2017-8f688120afe73ec3b25d31294b5886f5651bde2e.zip |
day23
-rw-r--r-- | day23.cc | 52 | ||||
-rw-r--r-- | day23.k | 3 | ||||
-rw-r--r-- | day23b.cc | 49 |
3 files changed, 104 insertions, 0 deletions
diff --git a/day23.cc b/day23.cc new file mode 100644 index 0000000..ae9b3e6 --- /dev/null +++ b/day23.cc @@ -0,0 +1,52 @@ +#include <array> +#include <iostream> +#include <string> +#include <algorithm> +#include <variant> +#include <vector> +#include <deque> +#include <memory> + +using namespace std; + +int +main() { + vector<string> code; + for (string line; getline(cin, line); ) + code.push_back(line); + + array<long, 256> reg{ 0 }; + + long p1 = 0, p2 = 0; + + for (auto ip = begin(code); ip != end(code); ip++) { + auto is_op = [&](string p) { + return equal(begin(p), end(p), begin(*ip)); + }; + + long tmp; + auto r = [&](int i) -> long& { + if (islower((*ip)[i])) + return reg[uint8_t((*ip)[i])]; + else { + tmp = stol(&(*ip)[i]); + return tmp; + } + }; + + if (is_op("set")) r(4) = r(6); + if (is_op("sub")) r(4) -= r(6); + if (is_op("mul")) r(4) *= r(6), p1++; + if (is_op("jnz") && r(4)) advance(ip, r(6) - 1); + } + + int c = 100'000 + 100 * stol(&code[0][6]); + for (int x = c; x <= c + 17'000; x += 17) + for (int i = 2; i < x; i++) + if (x % i == 0) { + p2++; + break; + } + + cout << p1 << endl << p2 << endl; // 8281 911 +} diff --git a/day23.k b/day23.k new file mode 100644 index 0000000..3696359 --- /dev/null +++ b/day23.k @@ -0,0 +1,3 @@ +/ just part 2 +#{0 in (2+!_%x)!\:x}#100000+(100*.*|" "\*0:`day23)+17*!1001 +\\ diff --git a/day23b.cc b/day23b.cc new file mode 100644 index 0000000..d796e4a --- /dev/null +++ b/day23b.cc @@ -0,0 +1,49 @@ +#include <iostream> + +int a, b, c, d, e, f, g, h; + +int +main() { + a = 1; + + b = 93; + c = b; + if (a) goto l5; + goto l9; +l5: b *= 100; + b -= -100000; + c = b; + c -= -17000; +l9: f = 1; std::cout << a << " " << b << " " << c << " " << h << std::endl; + d = 2; +l11: e = 2; +l12: g = d; + g *= e; + g -= b; + if (g) goto l17; + f = 0; +#ifndef ORIGINAL + goto fix; +#endif +l17: e -= -1; + g = e; + g -= b; + if (g) goto l12; + d -= -1; + g = d; +#ifdef ORIGINAL + g -= b; +#else + g -= 350; +#endif + if (g) goto l11; +fix: if (f) goto l27; + h -= -1; +l27: g = b; + g -= c; + if (g) goto l31; + goto l33; +l31: b -= -17; + goto l9; +l33: std::cout << h << std::endl; +} |