Files
adventofcode/2022/day3_1.py
2022-12-04 07:27:32 +01:00

30 lines
550 B
Python

## Read input file
input = []
with open('day3_input.txt', 'r') as f:
for line in f.readlines():
input.append(line.strip())
# Solve problem
def run():
total = 0
for line in input:
l = int(len(line) / 2)
left, right = set(line[:l]), set(line[l:])
isect = left.intersection(right)
for i in isect:
common = i
if common.islower():
total += ord(common) - 96
else:
total += ord(common) - 38
print(total)
if __name__ == '__main__':
run()