day 18, compile with codon for speed
This commit is contained in:
parent
712049e929
commit
b360d60a05
12
d18/part2.py
12
d18/part2.py
|
@ -2,16 +2,18 @@ import sys
|
||||||
|
|
||||||
S = set() # cubes
|
S = set() # cubes
|
||||||
for l in sys.stdin.read().splitlines():
|
for l in sys.stdin.read().splitlines():
|
||||||
S.add(tuple(map(int,l.split(','))))
|
(x,y,z) = list(map(int,l.split(','))) # makes type of tuple explicite for codon
|
||||||
|
S.add((x,y,z))
|
||||||
|
|
||||||
A = 23
|
A = 23
|
||||||
L = set() # water
|
L = set() # water
|
||||||
for x in range(-2,A+1):
|
for x in range(-2,A+1):
|
||||||
for y in range(-2,A+1):
|
for y in range(-2,A+1):
|
||||||
L.add((x,y,-2))
|
L.add((x,y,-2))
|
||||||
|
|
||||||
more = True
|
more = True
|
||||||
while more:
|
while more:
|
||||||
c = 0
|
more = False
|
||||||
for x in range(-2,A+1):
|
for x in range(-2,A+1):
|
||||||
for y in range(-2,A+1):
|
for y in range(-2,A+1):
|
||||||
for z in range(-2,A+1):
|
for z in range(-2,A+1):
|
||||||
|
@ -19,9 +21,8 @@ while more:
|
||||||
for (i,j,k) in [(0,0,1),(0,0,-1),(0,1,0),(0,-1,0),(1,0,0),(-1,0,0)]:
|
for (i,j,k) in [(0,0,1),(0,0,-1),(0,1,0),(0,-1,0),(1,0,0),(-1,0,0)]:
|
||||||
if (x+i,y+j,z+k) in L: # if neighbour is water
|
if (x+i,y+j,z+k) in L: # if neighbour is water
|
||||||
L.add((x,y,z)) # water expand
|
L.add((x,y,z)) # water expand
|
||||||
c += 1
|
more = True
|
||||||
break
|
break
|
||||||
more = (c>0)
|
|
||||||
|
|
||||||
N = 0
|
N = 0
|
||||||
for (x,y,z) in S:
|
for (x,y,z) in S:
|
||||||
|
@ -30,5 +31,4 @@ for (x,y,z) in S:
|
||||||
N += 1
|
N += 1
|
||||||
print(N)
|
print(N)
|
||||||
|
|
||||||
# > 2489
|
# ~/.local/programs/codon/bin/codon build --relocation-model=static --release -o part2 part2.py
|
||||||
# > 2520
|
|
||||||
|
|
Loading…
Reference in New Issue