aoc2024/d05/part1.awk

30 lines
433 B
Awk
Raw Normal View History

NR == FNR {
# 47|53
#print $0, $1, "before", $2
O[$1] = O[$1] $2 ","
next
}
{
correct = 1
for (i=2;i<=NF;i++) {
if ($i in O)
split(O[$i],A,",")
for(j=1;j<i;j++) {
if ($i in O) {
if (index(O[$i],$j",")) {
correct = 0
}
}
}
}
if (!correct) {
print
}
S += correct * $((NF+1)/2)
}
END {
print S > "/dev/stderr"
}