Compare commits
No commits in common. '7b51a1da696e890cda6084fd781c799a64ea7e9c' and 'cea2400d6f500897f4eff4ad05612cc4f6abbeaf' have entirely different histories.
7b51a1da69
...
cea2400d6f
3 changed files with 8 additions and 82 deletions
@ -1,25 +0,0 @@ |
||||
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) |
@ -1,33 +0,0 @@ |
||||
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