@t=<>;sub Q{for(@t){chomp;$i=0;\x0d $_[$i++].=$1while s/(.)//}@_}@_=Q;$i=0;\x0d for(@_){$_.="\n";$i++;/^ ? ?#/&&push@m,$i}until($z){\x0d for$j(@m){$z++if$_[$j-1]=~/^ ? ?#+ (#|$)/}\x0d for$i(@m){$_[$i-1]=~s/# /#/}}\x0d for(@_){s/^/ /until/.{15}/}@t=@_;@_=Q;\x0d for(@_){/ /&&($_.="\n")||s/.//g&&$r++}\x0d print" "x10,"\n"while$r--;print@_
Note that non-ascii characters in the above source code will be escaped (such as \x9f).