This commit is contained in:
setop 2022-12-03 16:01:59 +01:00
parent bbc20bf8ce
commit c8c36a069e
3 changed files with 59 additions and 0 deletions

16
d03/part1.py Normal file
View File

@ -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()))

25
d03/part2.awk Normal file
View File

@ -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}

18
d03/part2.py Normal file
View File

@ -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()))