day 3, part 1 in awk and compat part 2
This commit is contained in:
parent
3f67d3091d
commit
aaece858e7
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
split(substr($0,1,length($0)/2),arr,"")
|
||||
r = substr($0,1+length($0)/2)
|
||||
for (a in arr) {
|
||||
c = arr[a]
|
||||
if (index(r,c)>0) {
|
||||
comm = c
|
||||
}
|
||||
}
|
||||
S += index("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", comm)
|
||||
}
|
||||
END {print S}
|
|
@ -1,25 +1,13 @@
|
|||
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, "")
|
||||
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,"")
|
||||
for (a in arr) {
|
||||
c = arr[a]
|
||||
if ((c in A) && (c in B)) {
|
||||
comm = c
|
||||
}
|
||||
if ((c in A)&&(c in B)) {comm = c}
|
||||
}
|
||||
i = index("abcdefghijklmnopqrstuvwxyz", comm)
|
||||
j = index("ABCDEFGHIJKLMNOPQRSTUVWXYZ", comm)+26
|
||||
S += i > 0 ? i : j
|
||||
S += index("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", comm)
|
||||
delete A
|
||||
delete B
|
||||
}
|
||||
END { print S}
|
||||
END {print S}
|
||||
|
|
Loading…
Reference in New Issue