straight line floodfill SIMPLIFIED by hallvabo

import os
def f(p,d):
 if t.get((p,d))<'#'!=a[p]:a[p]=t[p,d]='.';x=w**(d%w>0)*('#'==a[p+d]);[f(p+y,y)for y in-x,x,d]
t={}
a=list(os.read(0,999))
z=a.index
w=z('\n')+1
f(z('.'),w)
print''.join(a)

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page