summary refs log tree commit diff homepage
path: root/2022/day03.awk
blob: 6a4a153860deee954875ea4ca10a38402d68425e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function common(a, b) {
	split(a, as, "");
	for (i in as) {
		if (index(b, as[i])) return as[i];
	}
}
function priority(x) {
	return index("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", x);
}
{
	a = substr($1, 1, length($1)/2);
	b = substr($1, length($1)/2 + 1);
	sum += priority(common(a, b));
}
END {
	print sum;
}