aboutsummaryrefslogtreecommitdiff
path: root/2022/01/puzzle-2.awk
blob: d8bbaaa3314751123ce6a2d0a45be69a0a3841bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/awk -f

/[0-9]+/ { acc += $1; next }
{
	if (acc > max[1]) {
		max[3] = max[2];
		max[2] = max[1];
		max[1] = acc;
	} else if (acc > max[2]) {
		max[3] = max[2];
		max[2] = acc;
	} else if (acc > max[3])
		max[3] = acc;
	acc = 0
}

END { print max[1] + max[2] + max[3] }