2024 Dec 10th
This commit is contained in:
parent
d65743eeb2
commit
fbb492e3ae
1 changed files with 43 additions and 0 deletions
43
Python/2024/10/main.py
Normal file
43
Python/2024/10/main.py
Normal 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)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue