summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-12-02 10:42:14 -0500
committerJune McEnroe <june@causal.agency>2022-12-02 10:42:14 -0500
commit9c4cb7355b4489734b509b30e3b532d7df6723bb (patch)
tree9fe8310ce0c99aea9f9e08d7846a088ad9429004
parentSolve day 2 part 1 (diff)
downloadaoc-9c4cb7355b4489734b509b30e3b532d7df6723bb.tar.gz
aoc-9c4cb7355b4489734b509b30e3b532d7df6723bb.zip
Solve day 2 part 2
-rw-r--r--2022/day02.awk17
1 files changed, 15 insertions, 2 deletions
diff --git a/2022/day02.awk b/2022/day02.awk
index 3e349c3..d01b15d 100644
--- a/2022/day02.awk
+++ b/2022/day02.awk
@@ -13,8 +13,21 @@ function score(a, b) {
 {
 	a = index("ABC", $1);
 	b = index("XYZ", $2);
-	total += score(a, b);
+	total1 += score(a, b);
+	if (b == 1) {
+		if (a == 1) b = 3;
+		if (a == 2) b = 1;
+		if (a == 3) b = 2;
+	} else if (b == 2) {
+		b = a;
+	} else if (b == 3) {
+		if (a == 1) b = 2;
+		if (a == 2) b = 3;
+		if (a == 3) b = 1;
+	}
+	total2 += score(a, b);
 }
 END {
-	print total;
+	print total1;
+	print total2;
 }