Compare commits
2 Commits
08b0b82100
...
a578c4df97
| Author | SHA1 | Date | |
|---|---|---|---|
| a578c4df97 | |||
| 89bd320991 |
33
03/c.py
Normal file
33
03/c.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import os
|
||||
|
||||
f = open(os.path.dirname(__file__)+"/input.txt", "r")
|
||||
|
||||
tot = 0
|
||||
tot2 = 0
|
||||
|
||||
priorities = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
commons = ''
|
||||
|
||||
rucksacks = f.read().splitlines()
|
||||
rucksacks2 = []
|
||||
|
||||
for data in rucksacks:
|
||||
left = data[:len(data)//2]
|
||||
right = data[len(data)//2:]
|
||||
|
||||
common = ''.join(set(left).intersection(right))
|
||||
|
||||
tot = tot + priorities.rfind(common)+1
|
||||
|
||||
print("First answer: " + str(tot))
|
||||
|
||||
start = 0
|
||||
end = len(rucksacks)
|
||||
step = 3
|
||||
for i in range(start, end, step):
|
||||
|
||||
three = rucksacks[i:i+step]
|
||||
common = set(three[0]) & set(three[1]) & set(three[2])
|
||||
tot2 = tot2 + priorities.rfind(''.join(common))+1
|
||||
|
||||
print("Second answer: " + str(tot2))
|
||||
Reference in New Issue
Block a user