-
Notifications
You must be signed in to change notification settings - Fork 0
/
2321_unfinished.py
49 lines (44 loc) · 1.14 KB
/
2321_unfinished.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
F = 0
#//////////////////////////////////////////////////
#// part 2 pending //
#//////////////////////////////////////////////////
r1, r2 = 0, 0
A = []
import math
with open('21.' + str(F)) as file:
for line in file:A.append(line.strip())
def dbg( Thing, name=None ):
if name: print(name)
if isinstance(Thing, dict):
Dict = Thing
print(Dict)
for k,v in Dict.items(): print(k,v)
if isinstance(Thing, list):
things = Thing
print(things)
for thing in things: print( thing )
print()
start = (None, None)
R, C = len(A),len(A[0])
for r in range(R):
for c in range(C):
if A[r][c] == 'S': start = (r, c, 0)
dbg(A)
D = [ start ]
P,seen, = set(), {(r,c)} # P ~ plots
DR=[1,0,-1,0]
DC=[0,1,0,-1]
while D:
#dbg(D)
r,c,dist = D.pop(0)
if r < 0 or r > R - 1 or c < 0 or c > C - 1 or (r,c) in seen or A[r][c] == '#':
continue
seen.add((r,c))
if dist <= 64 and dist % 2 == 0:
P.add((r,c))
for i in range(4):
pos = (r + DR[i], c + DC[i], dist + 1)
D.append(pos)
r1 = len(P)
print("part 1:", r1)
print("part 2:", r2)