summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-12-04 18:00:16 -0500
committerJune McEnroe <june@causal.agency>2022-12-04 18:00:16 -0500
commit61c244e84dea782f17c2e7377c405e0ac4198cfc (patch)
treea0749a37290e623017777b34cc3a26a0d3c0b403
parentSolve day 2 part 2 (diff)
downloadaoc-61c244e84dea782f17c2e7377c405e0ac4198cfc.tar.gz
aoc-61c244e84dea782f17c2e7377c405e0ac4198cfc.zip
Solve day 3 part 1
Diffstat (limited to '')
-rw-r--r--2022/day03.awk17
1 files changed, 17 insertions, 0 deletions
diff --git a/2022/day03.awk b/2022/day03.awk
new file mode 100644
index 0000000..6a4a153
--- /dev/null
+++ b/2022/day03.awk
@@ -0,0 +1,17 @@
+function common(a, b) {
+	split(a, as, "");
+	for (i in as) {
+		if (index(b, as[i])) return as[i];
+	}
+}
+function priority(x) {
+	return index("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", x);
+}
+{
+	a = substr($1, 1, length($1)/2);
+	b = substr($1, length($1)/2 + 1);
+	sum += priority(common(a, b));
+}
+END {
+	print sum;
+}
June McEnroe 2019-12-21Add first working version of imboxJune McEnroe 2019-12-20Respect mailmap in gl pretty formatJune McEnroe 2019-12-20Set LANG in cgit filtersJune McEnroe 2019-12-20Source .editrc before applying -v or -eJune McEnroe 2019-12-20Disable signing commitsJune McEnroe 2019-12-19Ignore about-filterJune McEnroe 2019-12-19Fix matching make tags with no sourcesJune McEnroe 2019-12-19Avoid matching := assignments as tagsJune McEnroe 2019-12-18Hide line numbers when rendering mdocJune McEnroe 2019-12-18Customize cgit CSSJune McEnroe 2019-12-18Use :target rather than :focus pseudo-classJune McEnroe 2019-12-18Copy cgit auxiliary binaries properlyJune McEnroe 2019-12-18Add git.causal.agency cgit configJune McEnroe 2019-12-18Bail from hi if input is binaryJune McEnroe 2019-12-16Post "cgit setup"June McEnroe