summary refs log tree commit diff homepage
path: root/2022
diff options
context:
space:
mode:
Diffstat (limited to '2022')
-rw-r--r--2022/day12.awk58
1 files changed, 58 insertions, 0 deletions
diff --git a/2022/day12.awk b/2022/day12.awk
new file mode 100644
index 0000000..265fad6
--- /dev/null
+++ b/2022/day12.awk
@@ -0,0 +1,58 @@
+BEGIN {
+	FS = "";
+	y = 1;
+}
+function elev(a) {
+	return index("abcdefghijklmnopqrstuvwxyz", a);
+}
+{
+	for (x = 1; x <= NF; ++x) {
+		if ($x == "S") {
+			S = x "," y;
+			m[x,y] = elev("a");
+		} else if ($x == "E") {
+			E = x "," y;
+			m[x,y] = elev("z");
+		} else {
+			m[x,y] = elev($x);
+		}
+	}
+	y++;
+	w = NF;
+	h = NR;
+}
+END {
+	l = 1;
+	Q[l] = S;
+	N[l] = 0;
+	for (i = 1; Q[i]; ++i) {
+		if (Q[i] == E) break;
+		split(Q[i], a, ",");
+		x = a[1];
+		y = a[2];
+		n = N[i];
+		if (x > 1 && !V[x-1,y] && m[x-1,y] <= m[x,y]+1) {
+			V[x-1,y] = 1;
+			Q[++l] = x-1 "," y;
+			N[l] = n+1;
+		}
+		if (x < w && !V[x+1,y] && m[x+1,y] <= m[x,y]+1) {
+			V[x+1,y] = 1;
+			Q[++l] = x+1 "," y;
+			N[l] = n+1;
+		}
+		if (y > 1 && !V[x,y-1] && m[x,y-1] <= m[x,y]+1) {
+			V[x,y-1] = 1;
+			Q[++l] = x "," y-1;
+			N[l] = n+1;
+		}
+		if (y < h && !V[x,y+1] && m[x,y+1] <= m[x,y]+1) {
+			V[x,y+1] = 1;
+			Q[++l] = x "," y+1;
+			N[l] = n+1;
+		}
+		delete Q[i];
+		delete N[i];
+	}
+	print N[i];
+}
/td>Finish 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