summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--2022/day09.awk40
1 files changed, 40 insertions, 0 deletions
diff --git a/2022/day09.awk b/2022/day09.awk
new file mode 100644
index 0000000..95e4fb4
--- /dev/null
+++ b/2022/day09.awk
@@ -0,0 +1,40 @@
+BEGIN {
+	t[0,0] = 1;
+}
+function abs(x) {
+	if (x < 0) return -x;
+	return x;
+}
+function step() {
+	rx = tx-hx;
+	ry = ty-hy;
+	if (abs(rx) <= 1 && abs(ry) <= 1) return;
+	if (rx == 0) {
+		ty += (ry < 0 ? +1 : -1);
+	} else if (ry == 0) {
+		tx += (rx < 0 ? +1 : -1);
+	} else {
+		tx += (rx < 0 ? +1 : -1);
+		ty += (ry < 0 ? +1 : -1);
+	}
+	t[tx,ty] = 1;
+}
+{
+	dx = 0;
+	dy = 0;
+	if ($1 == "U") dy = -1;
+	if ($1 == "D") dy = +1;
+	if ($1 == "L") dx = -1;
+	if ($1 == "R") dx = +1;
+	for (i = 1; i <= $2; ++i) {
+		hx += dx;
+		hy += dy;
+		step();
+	}
+}
+END {
+	for (i in t) {
+		sum++;
+	}
+	print sum;
+}
le='2021-09-14 23:37:51 -0400'>2021-09-14Add downgrade IRC botJune McEnroe 2021-09-14Sort by title if authors matchJune McEnroe 2021-09-13Swap-remove tags as they're foundJune McEnroe 2021-09-12Replace htagml regex with strncmpJune McEnroe 2021-09-11Also defer printing comment for lone close-parensJune McEnroe 2021-09-10Publish "git-comment"June McEnroe 2021-09-10Add git comment --pretty optionJune McEnroe 2021-09-08Defer printing comment if line is blank or closing braceJune McEnroe 2021-09-08Up default min-repeat to 30 linesJune McEnroe 2021-09-08Handle dirty lines in git-commentJune McEnroe 2021-09-08Document and install git-commentJune McEnroe 2021-09-08Add repeat and all options to git-commentJune McEnroe 2021-09-08Add group threshold to git-commentJune McEnroe