Skip to main content
deleted 34 characters in body
Source Link
0xffcourse
  • 2.8k
  • 3
  • 14
  • 27

Python 2Python 3, 436421 bytes

l,e=len,enumerate
m=lambda n:{r=open(i,j0):y for i,x in e(n.split('\n'))for j,y in eread(x)}
n=lambda x:[(x[0]-1,x[1]),(x[0]+1,x[1]),(x[0],x[1]-1),(x[0],x[1]+1)]
defp=a={(i,j):y zfor i,x in e(r.split('\n'):
)for j,y in e(x)}
t=l(r.split('\n'));s=l(r.split('\n')[0]);a=p=m(r)
 for i in a:p=[p,i][a[i]=='P']
 w=[p]
 while l(w)!=r.count('#')+1:
  for x in a:
   if x in n(w[-1])and a[x]!=' 'and x not in w:w+=[x]
 a[w[(l(w)+1)//2]]='A';print ('\n'.join(''.join(a[j,i]for i in range(s))for j in range(t)))

Try it online!Try it online!

Python 2, 436 bytes

l,e=len,enumerate
m=lambda n:{(i,j):y for i,x in e(n.split('\n'))for j,y in e(x)}
n=lambda x:[(x[0]-1,x[1]),(x[0]+1,x[1]),(x[0],x[1]-1),(x[0],x[1]+1)]
def z(r):
 t=l(r.split('\n'));s=l(r.split('\n')[0]);a=p=m(r)
 for i in a:p=[p,i][a[i]=='P']
 w=[p]
 while l(w)!=r.count('#')+1:
  for x in a:
   if x in n(w[-1])and a[x]!=' 'and x not in w:w+=[x]
 a[w[(l(w)+1)//2]]='A';print '\n'.join(''.join(a[j,i]for i in range(s))for j in range(t))

Try it online!

Python 3, 421 bytes

l,e=len,enumerate
r=open(0).read()
n=lambda x:[(x[0]-1,x[1]),(x[0]+1,x[1]),(x[0],x[1]-1),(x[0],x[1]+1)]
p=a={(i,j):y for i,x in e(r.split('\n'))for j,y in e(x)}
t=l(r.split('\n'));s=l(r.split('\n')[0])
for i in a:p=[p,i][a[i]=='P']
w=[p]
while l(w)!=r.count('#')+1:
 for x in a:
  if x in n(w[-1])and a[x]!=' 'and x not in w:w+=[x]
a[w[(l(w)+1)//2]]='A';print('\n'.join(''.join(a[j,i]for i in range(s))for j in range(t)))

Try it online!

deleted 38 characters in body
Source Link
0xffcourse
  • 2.8k
  • 3
  • 14
  • 27

Python 2, 450436 bytes

e=enumeratel,e=len,enumerate
m=lambda n:{(i,j):y for i,x in e(n.split('\n'))for j,y in e(x)}
n=lambda x:[(x[0]-1,x[1]),(x[0]+1,x[1]),(x[0],x[1]-1),(x[0],x[1]+1)]
def z(r):
 t=lent=l(r.split('\n'))
 s=len;s=l(r.split('\n')[0])
 a=p=m;a=p=m(r)
 for i in a:p=[p,i][a[i]=='P']
 w=[p]
 while lenl(w)!=r.count('#')+1:
  for x in a:
   if x in n(w[-1])and a[x]!=' 'and x not in w:w+=[x]
 u=w[1:][a[w[(lenl(w)-1+1)//2]
 a[u]='A'
 print2]]='A';print '\n'.join(''.join(a[j,i]for i in range(s))for j in range(t))

Try it online!Try it online!

Python 2, 450 bytes

e=enumerate
m=lambda n:{(i,j):y for i,x in e(n.split('\n'))for j,y in e(x)}
n=lambda x:[(x[0]-1,x[1]),(x[0]+1,x[1]),(x[0],x[1]-1),(x[0],x[1]+1)]
def z(r):
 t=len(r.split('\n'))
 s=len(r.split('\n')[0])
 a=p=m(r)
 for i in a:p=[p,i][a[i]=='P']
 w=[p]
 while len(w)!=r.count('#')+1:
  for x in a:
   if x in n(w[-1])and a[x]!=' 'and x not in w:w+=[x]
 u=w[1:][(len(w)-1)//2]
 a[u]='A'
 print '\n'.join(''.join(a[j,i]for i in range(s))for j in range(t))

Try it online!

Python 2, 436 bytes

l,e=len,enumerate
m=lambda n:{(i,j):y for i,x in e(n.split('\n'))for j,y in e(x)}
n=lambda x:[(x[0]-1,x[1]),(x[0]+1,x[1]),(x[0],x[1]-1),(x[0],x[1]+1)]
def z(r):
 t=l(r.split('\n'));s=l(r.split('\n')[0]);a=p=m(r)
 for i in a:p=[p,i][a[i]=='P']
 w=[p]
 while l(w)!=r.count('#')+1:
  for x in a:
   if x in n(w[-1])and a[x]!=' 'and x not in w:w+=[x]
 a[w[(l(w)+1)//2]]='A';print '\n'.join(''.join(a[j,i]for i in range(s))for j in range(t))

Try it online!

added 24 characters in body
Source Link
0xffcourse
  • 2.8k
  • 3
  • 14
  • 27

Python 2, 438450 bytes

e=enumerate
m=lambda n:{(i,j):y for i,x in e(n.split('\n'))for j,y in e(x)}
n=lambda x:[(x[0]-1,x[1]),(x[0]+1,x[1]),(x[0],x[1]-1),(x[0],x[1]+1)]
r=inputdef z(r):
 t=len(r.split('\n'))
 s=len(r.split('\n')[0])
 a=p=m(r)
 for i in a:p=[p,i][a[i]=='P']
 w=[p]
 while len(w)!=r.count('#')+1:
  for x in a:
   if x in n(w[-1])and a[x]!=' 'and x not in w:w+=[x]
 u=w[1:][(len(w)-1)//2]
 a[u]='A'
print'\n' print '\n'.join(''.join(a[j,i]for i in range(s))for j in range(t))

Try it online!Try it online!

Python 2, 438 bytes

e=enumerate
m=lambda n:{(i,j):y for i,x in e(n.split('\n'))for j,y in e(x)}
n=lambda x:[(x[0]-1,x[1]),(x[0]+1,x[1]),(x[0],x[1]-1),(x[0],x[1]+1)]
r=input()
t=len(r.split('\n'))
s=len(r.split('\n')[0])
a=p=m(r)
for i in a:p=[p,i][a[i]=='P']
w=[p]
while len(w)!=r.count('#')+1:
 for x in a:
  if x in n(w[-1])and a[x]!=' 'and x not in w:w+=[x]
u=w[1:][(len(w)-1)//2]
a[u]='A'
print'\n'.join(''.join(a[j,i]for i in range(s))for j in range(t))

Try it online!

Python 2, 450 bytes

e=enumerate
m=lambda n:{(i,j):y for i,x in e(n.split('\n'))for j,y in e(x)}
n=lambda x:[(x[0]-1,x[1]),(x[0]+1,x[1]),(x[0],x[1]-1),(x[0],x[1]+1)]
def z(r):
 t=len(r.split('\n'))
 s=len(r.split('\n')[0])
 a=p=m(r)
 for i in a:p=[p,i][a[i]=='P']
 w=[p]
 while len(w)!=r.count('#')+1:
  for x in a:
   if x in n(w[-1])and a[x]!=' 'and x not in w:w+=[x]
 u=w[1:][(len(w)-1)//2]
 a[u]='A'
 print '\n'.join(''.join(a[j,i]for i in range(s))for j in range(t))

Try it online!

Source Link
0xffcourse
  • 2.8k
  • 3
  • 14
  • 27
Loading