summary refs log tree commit diff homepage
path: root/2022/day01.awk
blob: 0fbde52b19027689c5bf684b070399d706e0a96c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/[[:digit:]]+/ {
	cals += $1;
}
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 {
	push();
	print max1;
	print max1 + max2 + max3;
}