Compare commits

..

5 Commits

  1. 32
      2024/2.py
  2. 25
      2024/3.py
  3. 33
      2024/4.py

@ -2,10 +2,8 @@ lines = [[int(n) for n in l.split()] for l in open("input.txt", 'r').read().spli
unsafe, unsafe2 = 0, 0
for report in lines:
if report[0] == report[1]:
unsafe += 1
continue
def checksafe(report, recursive):
global unsafe, unsafe2
trend = -1 if report[0] > report[1] else 1
@ -14,8 +12,26 @@ for report in lines:
or (trend == 1 and report[i] > report[i+1]) \
or (report[i] == report[i+1]) \
or (abs(report[i] - report[i+1]) > 3):
unsafe += 1
break
if recursive:
return False
else:
unsafe += 1
# ????????? there's no way this is how this is should be done
if not (checksafe(l[:i-1] + l[i:], True) or checksafe(l[:i] + l[i+1:], True) or checksafe(l[:i+1] + l[i+2:], True)):
unsafe2 += 1
return False
return True
return True
for l in lines:
if l[0] == l[1]:
unsafe += 1
if not (checksafe(l[1:], True) or checksafe(l[:1] + l[2:], True)):
unsafe2 += 1
continue
else:
checksafe(l, False)
print(len(lines)-unsafe)
print(len(lines)-unsafe)
print(len(lines)-unsafe2)

@ -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…
Cancel
Save