day 18, was easy thanks to openscad
This commit is contained in:
parent
673ad56fd0
commit
72112e2311
|
@ -0,0 +1 @@
|
|||
{ print "translate([" $1+0.05 "," $2+0.05 "," $3+0.05 "]) cube([0.9,0.9,0.9]);" }
|
|
@ -0,0 +1,14 @@
|
|||
import sys
|
||||
|
||||
S = set()
|
||||
for l in sys.stdin.read().splitlines():
|
||||
S.add(tuple(map(int,l.split(','))))
|
||||
|
||||
N = 0
|
||||
for (x,y,z) in S:
|
||||
n = 6
|
||||
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 S:
|
||||
n -= 1
|
||||
N += n
|
||||
print(N)
|
|
@ -0,0 +1,34 @@
|
|||
import sys
|
||||
|
||||
S = set() # cubes
|
||||
for l in sys.stdin.read().splitlines():
|
||||
S.add(tuple(map(int,l.split(','))))
|
||||
|
||||
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
|
||||
for x in range(-2,A+1):
|
||||
for y in range(-2,A+1):
|
||||
for z in range(-2,A+1):
|
||||
if (x,y,z) not in S and (x,y,z) not in L: # water can only expand in air
|
||||
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
|
||||
break
|
||||
more = (c>0)
|
||||
|
||||
N = 0
|
||||
for (x,y,z) in S:
|
||||
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:
|
||||
N += 1
|
||||
print(N)
|
||||
|
||||
# > 2489
|
||||
# > 2520
|
Loading…
Reference in New Issue