summary refs log tree commit diff homepage
path: root/2022
diff options
context:
space:
mode:
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;
 }