AdventOfCode/2022/day3/day3_part2.py

22 lines
624 B
Python

import sys, pprint, string
arr = []
alpha=list(string.ascii_letters)
values_part1=[]
values_part2=[]
with open(sys.argv[1]) as f:
for l in f:
line=l.split()[0]
first, second = line[:len(line)//2],line[len(line)//2:]
shared=list(set(first)&set(second))[0]
index=alpha.index(shared)+1
values_part1.append(index)
arr.append([line,first,second,shared,int(index)])
print(sum(values_part1))
for i in range(0,len(arr),3):
shared=list(set(arr[i][0])&set(arr[i+1][0])&set(arr[i+2][0]))[0]
values_part2.append(int(alpha.index(shared)+1))
print(sum(values_part2))