summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-12-05 10:09:29 -0500
committerJune McEnroe <june@causal.agency>2022-12-05 10:09:29 -0500
commit498deb991b3774ecb79e34c574f8db6d4883164f (patch)
treead19b44ba69f8f441b795d971c3a72ac739abea5
parentSolve day 5 part 1 (diff)
downloadaoc-498deb991b3774ecb79e34c574f8db6d4883164f.tar.gz
aoc-498deb991b3774ecb79e34c574f8db6d4883164f.zip
Solve day 5 part 2
-rw-r--r--2022/day05.awk8
1 files changed, 8 insertions, 0 deletions
diff --git a/2022/day05.awk b/2022/day05.awk
index 599b1a4..34f8cc4 100644
--- a/2022/day05.awk
+++ b/2022/day05.awk
@@ -7,6 +7,7 @@
 		x = substr($i, 2, 1);
 		if (x == ".") continue;
 		a[i] = a[i] x;
+		b[i] = b[i] x;
 	}
 }
 /^move/ {
@@ -18,10 +19,17 @@
 		a[from] = substr(a[from], 2);
 		a[to] = x a[to];
 	}
+	x = substr(b[from], 1, count);
+	b[from] = substr(b[from], count+1);
+	b[to] = x b[to];
 }
 END {
 	for (i = 1; a[i]; i++) {
 		printf substr(a[i], 1, 1);
 	}
 	printf "\n";
+	for (i = 1; b[i]; i++) {
+		printf substr(b[i], 1, 1);
+	}
+	printf "\n";
 }