mirror of
https://github.com/jneug/adventofcode.git
synced 2026-04-14 06:43:33 +02:00
30 lines
550 B
Python
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()
|