mirror of
https://github.com/jneug/adventofcode.git
synced 2026-04-14 06:43:33 +02:00
2022: Day 1 - 4
This commit is contained in:
35
2022/day3_2.py
Normal file
35
2022/day3_2.py
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
## 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
|
||||
|
||||
group = []
|
||||
for line in input:
|
||||
if len(group) < 3:
|
||||
group.append(set(line))
|
||||
if len(group) == 3:
|
||||
isect = group[0].intersection(group[1], group[2])
|
||||
if len(isect) > 1:
|
||||
print(isect)
|
||||
|
||||
for i in isect:
|
||||
common = i
|
||||
if common.islower():
|
||||
total += ord(common) - 96
|
||||
else:
|
||||
total += ord(common) - 38
|
||||
group = []
|
||||
|
||||
print(total)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run()
|
||||
Reference in New Issue
Block a user