-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday3.py
More file actions
41 lines (37 loc) · 1.13 KB
/
day3.py
File metadata and controls
41 lines (37 loc) · 1.13 KB
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
import os
from pathlib import Path
the_day = 3
download_data_path = Path("/Users/relyea/Downloads/input.txt")
local_data_path = "/Users/relyea/code/advent_of_code_2022/input"+str(the_day)+".txt"
if download_data_path.exists():
download_data_path.rename(local_data_path)
with open(local_data_path) as input_file:
inpstring = input_file.readlines()
data = [
line.strip()
for line in inpstring
]
# the_sum = 0
# for line in data:
# linelen = len(line)
# first_set = set(line[0:int(linelen/2)])
# second_set = set(line[int(linelen/2):])
# intersect = first_set & second_set
# the_char = list(intersect)[0]
# if the_char.islower():
# the_sum += ord(the_char) - ord('a') + 1
# else:
# the_sum += ord(the_char) - ord('A') + 1
# print(the_sum)
the_sum = 0
for dd in range(int(len(data)/3)):
line1 = set(data[dd*3])
line2 = set(data[dd*3+1])
line3 = set(data[dd*3+2])
intersect = line1 & line2 & line3
the_char = list(intersect)[0]
if the_char.islower():
the_sum += ord(the_char) - ord('a') + 1
else:
the_sum += ord(the_char) - ord('A') + 1
print(the_sum)