From 9c4cb7355b4489734b509b30e3b532d7df6723bb Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Fri, 2 Dec 2022 10:42:14 -0500 Subject: Solve day 2 part 2 --- 2022/day02.awk | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to '2022') 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; } -- cgit 1.4.1