summary refs log tree commit diff homepage
path: root/2022/day04.awk
blob: 00b11f2519ecc4c45d68571c09045ef372044b6c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
BEGIN {
	FS = "[-,]";
}
function contains(a, b, x, y) {
	return x >= a && y <= b;
}
function overlaps(a, b, x, y) {
	return (x >= a && x <= b) || (y >= a && y <= b);
}
{
	if (contains($1, $2, $3, $4) || contains($3, $4, $1, $2)) pairs1++;
	if (overlaps($1, $2, $4, $4) || overlaps($3, $4, $1, $2)) pairs2++;
}
END {
	print pairs1;
	print pairs2;
}