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,24 +1,12 @@
|
||||||
NR %3 == 1 { split($0, arr, "")
|
NR%3==1 {split($0,arr,"");for(a in arr){A[arr[a]]=1}}
|
||||||
for (a in arr) {
|
NR%3==2 {split($0,arr,"");for(a in arr){B[arr[a]]=1}}
|
||||||
A[arr[a]]=1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
NR %3 == 2 { split($0, arr, "")
|
|
||||||
for (a in arr) {
|
|
||||||
B[arr[a]]=1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
NR%3==0 {
|
NR%3==0 {
|
||||||
split($0,arr,"")
|
split($0,arr,"")
|
||||||
for (a in arr) {
|
for (a in arr) {
|
||||||
c = arr[a]
|
c = arr[a]
|
||||||
if ((c in A) && (c in B)) {
|
if ((c in A)&&(c in B)) {comm = c}
|
||||||
comm = c
|
|
||||||
}
|
}
|
||||||
}
|
S += index("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", comm)
|
||||||
i = index("abcdefghijklmnopqrstuvwxyz", comm)
|
|
||||||
j = index("ABCDEFGHIJKLMNOPQRSTUVWXYZ", comm)+26
|
|
||||||
S += i > 0 ? i : j
|
|
||||||
delete A
|
delete A
|
||||||
delete B
|
delete B
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue