-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday3.py
63 lines (47 loc) · 1.16 KB
/
day3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import util
import numpy as np
test_data: [str] = \
"""vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw"""
def task1(input):
total = 0
for line in input:
l = len(line) // 2
f = line[0:l]
s = line[l:]
for c in s:
if c in f:
if c < 'a':
total += ord(c) - ord('A') + 27
else:
total += ord(c) - ord('a') + 1
break
return total
def task2(input):
total = 0
for i in range(0, len(input), 3):
a = input[i]
b = input[i + 1]
c = input[i + 2]
for ch in a:
if ch in b and ch in c:
break
if ch < 'a':
total += ord(ch) - ord('A') + 27
else:
total += ord(ch) - ord('a') + 1
return total
def parse(data: str):
return util.as_lines(data)
def main():
data: [str] = util.get(3, 2022)
# data = test_data
input = parse(data)
print(task1(input))
print(task2(input))
if __name__ == "__main__":
main()