about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--day23.cc52
-rw-r--r--day23.k3
-rw-r--r--day23b.cc49
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;
+}