summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-12-09 10:45:26 -0500
committerJune McEnroe <june@causal.agency>2022-12-09 10:45:26 -0500
commit07cb5d600ab821237db07fff109ac7c5e640aa88 (patch)
tree4772496fd689147fd5ec84e39f214f082c133f3d
parentSolve day 8 part 2 (diff)
downloadaoc-07cb5d600ab821237db07fff109ac7c5e640aa88.tar.gz
aoc-07cb5d600ab821237db07fff109ac7c5e640aa88.zip
Solve day 9 part 1
-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;
+}
d=0e2a09e0f33fc9c5fd780e90bcf0b98395f94c2a&follow=1'>Clean up atom.c and fix base URLsJune McEnroe Base URL should not be URL escaped! 2020-04-26Clean up archive.cJune McEnroe 2020-04-26Add -q to exit non-zero on early exitJune McEnroe 2020-04-26Rearrange some of archive.hJune McEnroe 2020-04-26Free part.parts.ptrJune McEnroe Oops. 2020-04-26Rename part->id to part->contentIDJune McEnroe Disambiguate with messageID. 2020-04-26Iterate through nested multiparts to find content for AtomJune McEnroe Also fixes content for multipart/signed. 2020-04-26Include Cc address in reply mailtosJune McEnroe 2020-04-26Use %R for RFC numbers in STANDARDS sectionJune McEnroe 2020-04-26Add mailto spec to STANDARDSJune McEnroe 2020-04-26Increase space between nav itemsJune McEnroe 2020-04-26Add mailto address for the archiveJune McEnroe 2020-04-26Put dates on new lines in indexJune McEnroe 2020-04-26Include <> around Message-Id in mailto: URLsJune McEnroe 2020-04-26Add link to index on thread pagesJune McEnroe 2020-04-26Fall back to Content-Type name parameter for attachmentsJune McEnroe 2020-04-26Remove margins in article.message headerJune McEnroe 2020-04-26Generate index.atomJune McEnroe 2020-04-26Generate XHTML content in Atom entriesJune McEnroe 2020-04-25Style index pageJune McEnroe 2020-04-25Render index.htmlJune McEnroe 2020-04-25Wrap <summary> replies count in <data>June McEnroe 2020-04-25Accumulate thread envelopes before concatenationJune McEnroe 2020-04-24Free envelope in concatDataJune McEnroe 2020-04-24Use replyTo address in mailto:June McEnroe 2020-04-23Wrap quoted lines in <q>June McEnroe