summary refs log tree commit diff homepage
path: root/2022/day02.awk
blob: 3e349c39bd0f2a48f09fce93a8c61e6ddf21ed6c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function outcome(a, b) {
	if (a == 1 && b == 3) return 0;
	if (a == 2 && b == 1) return 0;
	if (a == 3 && b == 2) return 0;
	if (b == 1 && a == 3) return 6;
	if (b == 2 && a == 1) return 6;
	if (b == 3 && a == 2) return 6;
	return 3;
}
function score(a, b) {
	return b + outcome(a, b);
}
{
	a = index("ABC", $1);
	b = index("XYZ", $2);
	total += score(a, b);
}
END {
	print total;
}