人材獲得作戦.sed

http://okajima.air-nifty.com/b/2010/01/post-abc6.html

適当に sed で解いてみた。サイズ決め打ちで書いたら割と簡単だった…

H
${

x

# initialize seen positions
h
x
s/.\(.\{25\}\).S.\(.\{25\}\)./*\1***\2*/
x

# initialize initial state of the queue
s/S /SN/
/N/{H;s/N/ /}
s/ S/NS/
/N/{H;s/N/ /}
s/\(S.\{26\}\) /\1N/
/N/{H;s/N/ /}
s/ \(.\{26\}S\)/N\1/
/N/{H;s/N/ /}

# add the marker
x
s/^\n/-&/
s/\n\n/\n=\n/
x

:

# load the queue
g
s/\n\n.*//

# done?
/NG\|GN\|N.\{26\}G\|G.\{26\}N/{
s/.*=\n//
s/N/$/
q
}

# check right
s/ \(.\{351\}\)N /%\1$N/
/%/{
s/%/*/
H
x
s/\n-.*=/\n/
x
}

G
s/=.*=/=/
s/\n\n.*//

# check left
s/ \(.\{352\}\) N/%\1N$/
/%/{
s/%/*/
H
x
s/\n-.*=/\n/
x
}

G
s/=.*=/=/
s/\n\n.*//

# check above
s/ \(.\{352\}\) \(.\{26\}\)N/%\1N\2$/
/%/{
s/%/*/
H
x
s/\n-.*=/\n/
x
}

G
s/=.*=/=/
s/\n\n.*//

# check below
s/.\(.\{325\}\)N\(.\{26\}\) /%\1$\2N/
/%/{
s/%/*/
H
x
s/\n-.*=/\n/
x
}

s/=.*//
G
s/\n\n/\n%\n/
/\n\n/{
s/\n\n/\n%\n/
s/%.*%/=/
x
b
}

i no way
d

}
d

サイズ決め打ちじゃなければ結構ややこしくなると思うけど、まぁできる範囲じゃないかな。

なにかあれば下記メールアドレスへ。
shinichiro.hamaji _at_ gmail.com
shinichiro.h