aoc2022/d03/part2.awk

14 lines
317 B
Awk
Raw Permalink Normal View History

2022-12-04 16:57:20 +00:00
NR%3==1 {split($0,arr,"");for(a in arr){A[arr[a]]=1}}
NR%3==2 {split($0,arr,"");for(a in arr){B[arr[a]]=1}}
NR%3==0 {
split($0,arr,"")
2022-12-03 15:01:59 +00:00
for (a in arr) {
c = arr[a]
2022-12-04 16:57:20 +00:00
if ((c in A)&&(c in B)) {comm = c}
2022-12-03 15:01:59 +00:00
}
2022-12-04 16:57:20 +00:00
S += index("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", comm)
2022-12-03 15:01:59 +00:00
delete A
delete B
}
2022-12-04 16:57:20 +00:00
END {print S}