2024 Dec 10th

This commit is contained in:
Julia Lange 2024-12-09 21:35:04 -08:00
parent d65743eeb2
commit fbb492e3ae
Signed by: Julia
SSH key fingerprint: SHA256:KI8YxpkPRbnDRkXPgCuQCVz181++Vy7NAvmQj8alOhM

43
Python/2024/10/main.py Normal file
View file

@ -0,0 +1,43 @@
input = open("input", 'r')
# d = [line for line in input]
# d = [[val for val in line.strip()] for line in input]
d = {(complex(x,y)): int(c) for y,line in enumerate(input) for x,c in enumerate(line.strip())}
z = [p for p,c in d.items() if c == 0]
# print(d, z)
def run(p2=False):
scores = []
ratings = []
for zero in z:
score = 0
q = []
s = set()
nines = set()
nines2 = 0
q.append(zero)
while q:
point = q.pop()
if d[point] == 9:
nines.add(point)
nines2 += 1
continue
if not p2 and point in s:
continue
s.add(point)
for dt in {1, -1, 1j, -1j}:
np = point + dt
if not np in d: continue
if d[np] == (d[point] + 1):
q.append(np)
scores.append(len(nines))
ratings.append(nines2)
return scores if not p2 else ratings
print(sum(run()))
print(sum(run(True)))