From b360d60a055c256ad233df5f0c286ee7185be4ae Mon Sep 17 00:00:00 2001 From: setop Date: Mon, 12 Jun 2023 12:49:11 +0200 Subject: [PATCH] day 18, compile with codon for speed --- d18/part2.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/d18/part2.py b/d18/part2.py index ad8bbf4..4ef1f79 100644 --- a/d18/part2.py +++ b/d18/part2.py @@ -2,16 +2,18 @@ import sys S = set() # cubes 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 L = set() # water for x in range(-2,A+1): for y in range(-2,A+1): L.add((x,y,-2)) + more = True while more: - c = 0 + more = False for x in range(-2,A+1): for y 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)]: if (x+i,y+j,z+k) in L: # if neighbour is water L.add((x,y,z)) # water expand - c += 1 + more = True break - more = (c>0) N = 0 for (x,y,z) in S: @@ -30,5 +31,4 @@ for (x,y,z) in S: N += 1 print(N) -# > 2489 -# > 2520 +# ~/.local/programs/codon/bin/codon build --relocation-model=static --release -o part2 part2.py