Moved 2022 to own dir
This commit is contained in:
21
2022/03/c.py
Normal file
21
2022/03/c.py
Normal file
@@ -0,0 +1,21 @@
|
||||
import os
|
||||
|
||||
rucksacks = open(os.path.dirname(__file__) +
|
||||
"/input.txt", "r").read().splitlines()
|
||||
|
||||
tot, tot2 = 0, 0
|
||||
|
||||
priorities = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
|
||||
for data in rucksacks:
|
||||
tot += priorities.rfind(''.join(set(data[:len(data)//2])
|
||||
& set(data[len(data)//2:])))+1
|
||||
|
||||
print("First answer: " + str(tot))
|
||||
|
||||
for i in range(0, len(rucksacks), 3):
|
||||
three = rucksacks[i:i+3]
|
||||
tot2 += priorities.rfind(''.join(set(three[0])
|
||||
& set(three[1]) & set(three[2])))+1
|
||||
|
||||
print("Second answer: " + str(tot2))
|
||||
Reference in New Issue
Block a user