summary refs log tree commit diff homepage
path: root/2022
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-12-01 14:22:44 -0500
committerJune McEnroe <june@causal.agency>2022-12-01 14:22:44 -0500
commit164e6b0fda3bf792af6ac0d8d2bc30200b805f79 (patch)
tree87930ccda3460603cdff73040b7a525638e6b671 /2022
parentSolve day 1 part 1 (diff)
downloadaoc-164e6b0fda3bf792af6ac0d8d2bc30200b805f79.tar.gz
aoc-164e6b0fda3bf792af6ac0d8d2bc30200b805f79.zip
Solve day 1 part 2
Diffstat (limited to '2022')
-rw-r--r--2022/day01.awk20
1 files changed, 17 insertions, 3 deletions
diff --git a/2022/day01.awk b/2022/day01.awk
index c81d624..0fbde52 100644
--- a/2022/day01.awk
+++ b/2022/day01.awk
@@ -1,10 +1,24 @@
 /[[:digit:]]+/ {
 	cals += $1;
 }
-/^$/ {
-	if (cals > max) max = cals;
+function push() {
+	if (cals > max1) {
+		max3 = max2;
+		max2 = max1;
+		max1 = cals;
+	} else if (cals > max2) {
+		max1 = max2;
+		max2 = cals;
+	} else if (cals > max3) {
+		max3 = cals;
+	}
 	cals = 0;
 }
+/^$/ {
+	push();
+}
 END {
-	print max;
+	push();
+	print max1;
+	print max1 + max2 + max3;
 }