day 3
This commit is contained in:
parent
bbc20bf8ce
commit
c8c36a069e
|
@ -0,0 +1,16 @@
|
|||
import sys
|
||||
|
||||
def p(c):
|
||||
o = ord(c)
|
||||
if o > 96:
|
||||
return o-96
|
||||
else:
|
||||
return o-64+26
|
||||
|
||||
def gen():
|
||||
for line in sys.stdin:
|
||||
(l,r) = line[:len(line)//2], line[len(line)//2:-1]
|
||||
b = set(l) & set(r)
|
||||
yield list(b)[0]
|
||||
|
||||
print(sum(p(c) for c in gen()))
|
|
@ -0,0 +1,25 @@
|
|||
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
|
||||
}
|
||||
}
|
||||
i = index("abcdefghijklmnopqrstuvwxyz", comm)
|
||||
j = index("ABCDEFGHIJKLMNOPQRSTUVWXYZ", comm)+26
|
||||
S += i > 0 ? i : j
|
||||
delete A
|
||||
delete B
|
||||
}
|
||||
END { print S}
|
|
@ -0,0 +1,18 @@
|
|||
import sys
|
||||
|
||||
def p(c):
|
||||
o = ord(c)
|
||||
if o > 96:
|
||||
return o-96
|
||||
else:
|
||||
return o-64+26
|
||||
|
||||
def gen():
|
||||
for _ in range(100):
|
||||
g1 = next(sys.stdin)[:-1]
|
||||
g2 = next(sys.stdin)[:-1]
|
||||
g3 = next(sys.stdin)[:-1]
|
||||
b = set(g1) & set(g2) & set(g3)
|
||||
yield list(b)[0]
|
||||
|
||||
print(sum(p(c) for c in gen()))
|
Loading…
Reference in New Issue