summary refs log tree commit diff homepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--2020/day14.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/2020/day14.c b/2020/day14.c
index f04e864..a40bb3f 100644
--- a/2020/day14.c
+++ b/2020/day14.c
@@ -1,7 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 typedef unsigned long ul;
-static struct {
+static struct Write {
 	ul addr;
 	ul val;
 } writes[1024];
@@ -16,6 +16,18 @@ static void write(ul addr, ul val) {
 	writes[len].addr = addr;
 	writes[len++].val = val;
 }
+static struct Write writes2[0xFFFFFFFFF];
+static ul len2;
+static void write2(ul addr, ul val) {
+	for (int i = 0; i < len2; ++i) {
+		if (writes2[i].addr == addr) {
+			writes2[i].val = val;
+			return;
+		}
+	}
+	writes2[len2].addr = addr;
+	writes2[len2++].val = val;
+}
 int main(void) {
 	ul mask = 0;
 	ul bits = 0;
@@ -37,9 +49,21 @@ int main(void) {
 			ul addr, val;
 			n = scanf("em[%lu] = %lu\n", &addr, &val);
 			if (n < 2) break;
-			val &= mask;
-			val |= bits;
-			write(addr, val);
+			write(addr, (val & mask) | bits);
+			addr |= bits;
+			addr &= ~mask;
+			ul writes = 1UL << __builtin_popcountl(mask);
+			for (ul i = 0; i < writes; ++i) {
+				ul a = addr;
+				ul w = i;
+				for (int j = 0; j < 36; ++j) {
+					if (mask & (1UL << j)) {
+						a |= (w & 1) << j;
+						w >>= 1;
+					}
+				}
+				write2(a, val);
+			}
 		}
 	}
 	ul sum = 0;
@@ -47,4 +71,9 @@ int main(void) {
 		sum += writes[i].val;
 	}
 	printf("%lu\n", sum);
+	sum = 0;
+	for (ul i = 0; i < len2; ++i) {
+		sum += writes2[i].val;
+	}
+	printf("%lu\n", sum);
 }
w the F row registers... I wonder if I can do something about that. 2021-02-07Set X key repeat rateJune McEnroe 2021-02-07Bump font size to 12June McEnroe 11 is what I use on macOS, but I feel like my eyes are working harder here. 2021-02-07Fully configure and rebind cwmJune McEnroe This is sort of a mix of trying to emulate macOS somewhat for my muscle memory and just rebinding some of the cwm defaults to use 4- rather than M-. 2021-02-07Add BintiJune McEnroe 2021-02-07Finish configuring xtermJune McEnroe 2021-02-06Enable tapping, reverse scroll, set scaling in wsconsctlJune McEnroe 2021-02-06Set root window to black on purple snowJune McEnroe 2021-02-06Add xmodmap configurationJune McEnroe 2021-02-06Add initial OpenBSD X configurationJune McEnroe cwm still needs a lot more rebinding, and I need to actually look at its other options. xterm definitely still needs some configuration, but I at least managed to get it to use a decent looking font. Very happy that OpenBSD includes Luxi Mono, which is what my usual font, Go Mono, is based on anyway. Still missing is xmodmap and such. 2021-02-06Add xterm output to schemeJune McEnroe