day 2, part 2!
parent
b4b2a6b675
commit
89d71d4946
@ -0,0 +1,68 @@
|
||||
BEGIN{ RS = ""; FS="" }
|
||||
|
||||
NR==1{
|
||||
for(i=1;i<=NF;i++){
|
||||
en[i-1] = $i=="#" ? 1 : 0
|
||||
}
|
||||
RS = "\n"
|
||||
next
|
||||
}
|
||||
|
||||
{
|
||||
for(i=-1;i<=NF+2;i++){
|
||||
if(i>=1 && i<=NF)
|
||||
inp[i,NR-1] = $i=="#" ? 1 : 0
|
||||
else
|
||||
inp[i,NR-1] = 0
|
||||
}
|
||||
}
|
||||
|
||||
function wintonum(px,py){
|
||||
nbit = 8; num=0
|
||||
for(j=py-1;j<=py+1;j++){
|
||||
for(i=px-1;i<=px+1;i++){
|
||||
b = inp[i,j]=="" ? 0 : inp[i,j]
|
||||
num += lshift( b, nbit)
|
||||
nbit--
|
||||
}
|
||||
}
|
||||
return num
|
||||
}
|
||||
|
||||
function wintonum2(px,py,pss){
|
||||
nbit = 8; num=0
|
||||
for(j=py-1;j<=py+1;j++){
|
||||
for(i=px-1;i<=px+1;i++){
|
||||
b = inp[i,j]=="" ? (pss%2==0? en[0] : 0 ) : inp[i,j]
|
||||
num += lshift( b, nbit)
|
||||
nbit--
|
||||
}
|
||||
}
|
||||
return num
|
||||
}
|
||||
|
||||
END{
|
||||
xmin=-1; xmax=NF+2
|
||||
ymin=-1; ymax=NR+1
|
||||
|
||||
for(pass=1;pass<=50;pass++){
|
||||
|
||||
count = 0
|
||||
for(y=ymin-pass; y<=ymax+pass; y++){
|
||||
for(x=xmin-pass; x<=xmax+pass; x++){
|
||||
wn = (pass==1) ? wintonum(x,y) : wintonum2(x,y,pass)
|
||||
newinp[x,y] = en[ wn ]
|
||||
count += en[ wn ]
|
||||
# printf "%c", newinp[x,y]==1? "#" : "."
|
||||
}
|
||||
# print ""
|
||||
}
|
||||
print "pass",pass,"count:",count
|
||||
|
||||
delete inp
|
||||
# copy result
|
||||
for(p in newinp) inp[p] = newinp[p]
|
||||
delete newinp
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue