day 3 second answer and clean up
This commit is contained in:
17
03/c.py
17
03/c.py
@@ -6,19 +6,28 @@ tot = 0
|
|||||||
tot2 = 0
|
tot2 = 0
|
||||||
|
|
||||||
priorities = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
priorities = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
|
||||||
|
|
||||||
commons = ''
|
commons = ''
|
||||||
|
|
||||||
rucksacks = f.read().splitlines()
|
rucksacks = f.read().splitlines()
|
||||||
|
rucksacks2 = []
|
||||||
|
|
||||||
for data in rucksacks:
|
for data in rucksacks:
|
||||||
left = data[:len(data)//2]
|
left = data[:len(data)//2]
|
||||||
right = data[len(data)//2:]
|
right = data[len(data)//2:]
|
||||||
print(str(left) + " " + str(right))
|
|
||||||
|
|
||||||
common = ''.join(set(left).intersection(right))
|
common = ''.join(set(left).intersection(right))
|
||||||
|
|
||||||
tot = tot + priorities.rfind(common)+1
|
tot = tot + priorities.rfind(common)+1
|
||||||
|
|
||||||
print(tot)
|
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