Compare commits
5 Commits
cea2400d6f
...
7b51a1da69
Author | SHA1 | Date |
---|---|---|
kwout | 7b51a1da69 | 1 month ago |
kwout | 06ae784a2b | 1 month ago |
kwout | 91f8845a23 | 1 month ago |
kwout | d1f87266e1 | 1 month ago |
kwout | c37f6ef263 | 1 month ago |
3 changed files with 82 additions and 8 deletions
@ -0,0 +1,25 @@ |
|||||||
|
import re |
||||||
|
|
||||||
|
lines = [l for l in open("input.txt", 'r').read().splitlines()] |
||||||
|
|
||||||
|
summa, summa2, do = 0, 0, True |
||||||
|
|
||||||
|
for l in lines: |
||||||
|
x2 = [i.span() for i in re.finditer(r"mul\([0-9]{1,3},[0-9]{1,3}\)|do\(\)|don't\(\)", l)] |
||||||
|
|
||||||
|
for start,end in x2: |
||||||
|
if l[start:end] == 'do()': |
||||||
|
do = True |
||||||
|
elif l[start:end] == 'don\'t()': |
||||||
|
do = False |
||||||
|
elif do: |
||||||
|
tup = l[start:end].split(',') |
||||||
|
prod = int(tup[0][4:]) * int(tup[1][:-1]) |
||||||
|
summa2 += prod |
||||||
|
summa += prod |
||||||
|
else : |
||||||
|
tup = l[start:end].split(',') |
||||||
|
summa += int(tup[0][4:]) * int(tup[1][:-1]) |
||||||
|
|
||||||
|
print(summa) |
||||||
|
print(summa2) |
@ -0,0 +1,33 @@ |
|||||||
|
import re |
||||||
|
|
||||||
|
lines = [l for l in open("input.txt", 'r').read().splitlines()] |
||||||
|
|
||||||
|
linesVert, linesDiag1, linesDiag2 = [], [], [] |
||||||
|
count, count2, width = 0, 0, len(lines[0]) |
||||||
|
|
||||||
|
for i in range(width): |
||||||
|
string, string2, string3 = "", "", "" |
||||||
|
for j in range(len(lines)): |
||||||
|
string += lines[j][i] |
||||||
|
string2 += lines[j][(i+j)%width] |
||||||
|
string3 += lines[width-j-1][(i+j)%width] |
||||||
|
|
||||||
|
linesDiag1.append(string2[:width - i]) |
||||||
|
linesDiag1.append(string2[width - i:]) |
||||||
|
linesDiag2.append(string3[:width - i]) |
||||||
|
linesDiag2.append(string3[width - i:]) |
||||||
|
linesVert.append(string) |
||||||
|
|
||||||
|
for l in lines + linesVert + linesDiag1 + linesDiag2: |
||||||
|
count += len(re.findall(r"(?=(XMAS|SAMX))", l)) |
||||||
|
|
||||||
|
for i in range(width-2): |
||||||
|
for j in range(len(lines)-2): |
||||||
|
diag1 = lines[j][i] + lines[j+1][i+1] + lines[j+2][i+2] |
||||||
|
diag2 = lines[j+2][i] + lines[j+1][i+1] + lines[j][i+2] |
||||||
|
if re.search(r"MAS|SAM", diag1) != None and re.search(r"MAS|SAM", diag2) != None: |
||||||
|
count2 += 1 |
||||||
|
|
||||||
|
|
||||||
|
print(count) |
||||||
|
print(count2) |
Loading…
Reference in new issue