blob: 22a79be3b347804243da9ddd15dd30927ed82542 (
plain)
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
64
65
66
67
68
69
70
|
#!/usr/bin/env python3
# filename = "in/day03.ref"
filename = "in/day03.pzl"
res1 = 0
with open(filename) as f:
for line in f:
line = line.strip()
middle = int(len(line)/2)
first = line[:middle]
last = line[middle:]
print(first)
print(last)
d = dict()
for c in first:
d[c] = True
for c in last:
if c in d:
print(c)
if 'a' <= c <= 'z':
add = ord(c) - ord('a') + 1
print(add)
res1 += add
elif 'A' <= c <= 'Z':
add = ord(c) - ord('A') + 27
print(add)
res1 += add
break
res2 = 0
with open(filename) as f:
for line in f:
first = line.strip()
second = next(f).strip()
third = next(f).strip()
print(first)
print(second)
print(third)
s1 = set()
for c in first:
s1.add(c)
s2 = set()
for c in second:
s2.add(c)
s3 = set()
for c in third:
s3.add(c)
si = s1.intersection(s2)
sii = si.intersection(s3)
print(sii)
c = list(sii)[0]
if 'a' <= c <= 'z':
add = ord(c) - ord('a') + 1
print(add)
res2 += add
elif 'A' <= c <= 'Z':
add = ord(c) - ord('A') + 27
print(add)
res2 += add
print(res1)
print(res2)
|