advent-of-code/22/22.awk

38 lines
773 B
Awk

{
state = ($1=="on") ? 1 : 0
split($2,arr,",")
split(arr[1],x,/\.\./)
split(arr[2],y,/\.\./)
split(arr[3],z,/\.\./)
sub(/^.=/,"",x[1])
sub(/^.=/,"",y[1])
sub(/^.=/,"",z[1])
print x[1],x[2],y[1],y[2],z[1],z[2], state
c=0
iz = (strtonum(z[1])<-50) ? -50 : strtonum(z[1])
iy = (strtonum(y[1])<-50) ? -50 : strtonum(y[1])
ix = (strtonum(x[1])<-50) ? -50 : strtonum(x[1])
fz = (strtonum(z[2])>50) ? 50 : strtonum(z[2])
fy = (strtonum(y[2])>50) ? 50 : strtonum(y[2])
fx = (strtonum(x[2])>50) ? 50 : strtonum(x[2])
print iz
for(tz=iz;tz<=fz;tz++){
for(ty=iy;ty<=fy;ty++){
for(tx=ix;tx<=fx;tx++){
# printf "%d,%d,%d:%d\n", tx,ty,tz,state
cube[tx,ty,tz] = state;
c++
}
}
}
print c
}
END{
for(p in cube)
count += cube[p]
print count
}