2022 day 3b solved

kwout 11 months ago
parent e0c1596ed8
commit 650a7651ab
  1. 28
      2022/3.py

@ -2,14 +2,34 @@ lines = [i for i in open("input.txt", 'r').read().splitlines()]
letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
sum = 0
sum2 = 0
for l in lines:
for i in range(len(lines)):
l = lines[i]
found = False
for c in l[:int(len(l)/2)]:
for d in l[int(len(l)/2):]:
if c == d:
if not found:
sum += letters.index(c)+1
found = True
sum += letters.index(c)+1
found = True
break
if found:
break
found = False
if i % 3 == 0:
for c in l:
for d in lines[i+1]:
if c == d:
for e in lines[i+2]:
if d == e:
sum2 += letters.index(c)+1
found = True
break
if found:
break
if found:
break
print(sum)
print(sum2)
Loading…
Cancel
Save