day 18, compile with codon for speed

This commit is contained in:
setop 2023-06-12 12:49:11 +02:00
parent 712049e929
commit b360d60a05
1 changed files with 6 additions and 6 deletions

View File

@ -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