| Bytes | Lang | Time | Link |
|---|---|---|---|
| 079 | Dyalog APL | 250801T205309Z | Aaron |
| 241 | Python | 120604T003919Z | edwkar |
| 207 | Ruby | 120601T125207Z | Cristian |
| 168 | Ruby | 120604T090703Z | Howard |
| 563 | C# | 120412T160704Z | Cristian |
| 257 | PHP | 120412T200208Z | Rusty Fa |
| 259 | Python | 120412T210145Z | Keith Ra |
| 410 | Javascript | 120412T160156Z | Ed James |
Dyalog APL, 90 79 chars
{g⊣g[x]←⍵[x]⊣x←⍸'x'=g←{' @;<d>bxxV>YxFxxx'⌷⍨1+(5⌷,⍵)×1+2⊥(⊂2×⍳4)⌷,⍵}⌺3 3⊢' '≠⍵}
Bit of a doozy this one, but was fun and I feel like I, for once, applied stencil correctly
Explanation, separating out magic string for clarity:
m←' @;<d>bxxV>YxFxxx'
{g⊣g[x]←⍵[x]⊣x←⍸'x'=g←{m⌷⍨1+(5⌷,⍵)×1+2⊥(⊂2×⍳4)⌷,⍵}⌺3 3⊢' '≠⍵}
' '≠⍵ Find the non-whitespace
{ }⌺3 3⊢ Stencil over with a 3x3 window
(⊂2×⍳4)⌷,⍵ Get the N, S, E, and W indices (corresponding to 2 4 6 8 in the 3x3 window
2⊥ Decode that as if it were binary
1+ Add 1 because a zero here will screw me up later
(5⌷,⍵) Get the center of the stencil (the element being examined)
× Multiply these (as in, if it was whitespace, always map to zero)
m⌷⍨1+ Add one for indexing sake and pull from the magic string
g← Store all that in g for a minute
'x'= Find those which became 'x', the "untouched"
x←⍸ Get the indices of those elements, aptly stored in x
g[x]←⍵[x]⊣ Replace all of those indices with the corresponding element from the original input
g⊣ And finally show that sucker
Python, 246 241
H=input();W=1+input()
S=' '
o=W*S
F=o+'\n'.join((raw_input()+o)[:W-1]for k in range(H))+o
print ''.join((16*x+'@;<d>b'+2*x+'V'+x+'Y'+x+'F'+3*x)[
16*(x>S)|8*(a>S)|4*(l>S)|2*(r>S)|(b>S)]for
x,a,l,r,b in zip(F[W:-W],F,F[W-1:],F[W+1:],F[2*W:]))
WC and test on sample 2, diffed with the output of the Ruby solution at the top:
t:~$ wc trans.py && python trans.py < lala2 > o && diff -q o ruby_out2_sample
2 11 241 trans.py
t:~$
Ruby 275 265 263 261 258 254 244 243 214 212 207
H=0...gets.to_i
W=0...gets.to_i
G=readlines
z=->x,y{(H===y&&W===x&&' '!=G[y][x])?1:0}
H.map{|j|W.map{|i|l=G[j][i]
G[j][i]="@V;#{l}>Fb#{l}<Yd#{l*5}"[z[i+1,j]*8+z[i-1,j]*4+z[i,j+1]*2+z[i,j-1]]if' '!=l}}
puts G
Sample 1: http://ideone.com/PfNMA
Sample 2: http://ideone.com/sWijD
Ruby, 180 168 characters
gets
w=1+gets.to_i
f=*(readlines*"").chars
f.zip(f[1..-1]+s=[" "],s+f,s*w+f,f[w..-1]+s*w){|a,*b|$><<"@;V#{a}>bF#{a}<dY#{a*5}"[a>" "?(b.map{|y|y>" "?1:0}*"").to_i(2):3]}
Another Ruby implementation which takes a zip approach. You can see the second example running online.
Edit: Using readlines saves 12 characters.
C# 591 563
string A(string t){var s=new StringReader(t);var h=int.Parse(s.ReadLine());var w=int.Parse(s.ReadLine());var lines=s.ReadToEnd().Split(new[]{"\r\n"},StringSplitOptions.None).Select(x=>x.ToCharArray()).ToArray();for(var i=0;i<h;i++)for(var j=0;j<w;j++){var c=lines[i][j];if(c==' ')continue;var n=(i>0?(lines[i-1][j]!=' '?1:0):0)+(i<h-1?(lines[i+1][j]!=' '?2:0):0)+(j>0?(lines[i][j-1]!=' '?4:0):0)+(j<w-1?(lines[i][j+1]!=' '?8:0):0);lines[i][j]=new[]{'@','V',';',c,'>','F','b',c,'<','Y','d',c,c,c,c,c}[n];}return string.Join("\r\n",lines.Select(l=>new string(l)));}
PHP - 359 330 282 268 257 characters
<?php
$i=fgets(STDIN)+0;$w=fgets(STDIN)+1;$s='';$m='@<;d>0b0VY00F000';
for(;$i--;)$s.=fgets(STDIN);
for(;++$i<strlen($s);){
$b=trim($s[$i])?0:15;
foreach(array($i+1,$i+$w,$i-1,$i-$w)as$k=>$x)
$b|=pow(2,$k)*(isset($s[$x])&&trim($s[$x]));
echo $m[$b]?$m[$b]:$s[$i];}
Python, 259 chars
H=input()
W=input()+1
I=' '.join(raw_input()for i in' '*H)
for i in range(H):print''.join(map(lambda(s,a,b,c,d):(s*5+'dY<'+s+'bF>'+s+';V@'+' '*16)[16*(s==' ')+8*(a==' ')+4*(b==' ')+2*(c==' ')+(d==' ')],zip(I,I[1:]+' ',' '+I,I[W:]+' '*W,' '*W+I))[i*W:i*W+W-1])
The program reads the input into a single string I (with spaces separating the lines), zips up a list of 5-tuples containing the character and its four surrounding characters, then looks up the result character using string indexing.
Javascript, 410 characters:
function(t){m={"10110":"b","11100":"d","01101":"Y","00111":"F","10100":";","00101":"V","00110":">","01100":"<","00100":"@"},d="join",l="length",t=t.split('\n').splice(2),t=t.map(function(x)x.split('')),f=function(i,j)t[i]?(t[i][j]||' ')==' '?0:1:0;for(o=t[l];o--;){for(p=t[o][l];p--;){y=[f(o+1,p),f(o,p+1),f(o,p),f(o,p-1),f(o-1,p)],t[o][p]=m[y[d]('')]||t[o][p]}}t=t.map(function(x)x[d](''))[d]('\n');return t;}
ungolfed:
function(t){
m={
"10110":"b",
"11100":"d",
"01101":"Y",
"00111":"F",
"10100":";",
"00101":"V",
"00110":">",
"01100":"<",
"00100":"@"
},
d="join",
l="length",
t=t.split('\n').splice(2),
t=t.map(function(x) x.split('')),
f=function(i,j) t[i]?(t[i][j]||' ')==' '?0:1:0;
for(o=t[l];o--;){
for(p=t[o][l];p--;){
y=[f(o+1,p),f(o,p+1),f(o,p),f(o,p-1),f(o-1,p)],
t[o][p]=m[y[d]('')]||t[o][p]
}
}
t=t.map(function(x)x[d](''))[d]('\n');
return t;
}
Original, 440 characters:
function (t){m={"10110":"b","11100":"d","01101":"Y","00111":"F","10100":";","00101":"V","00110":">","01100":"<","00100":"@"},s="split",d="join",l="length",t=t[s]('\n').splice(2),t=t.map(function(x) x[s]('')),f=function(i,j)i<0||i>=t[l]?0:(j<0||j>=t[i][l]?0:t[i][j]==' '?0:1);for(o=t[l];o--;){for(p=t[o][l];p--;){y=[f(o+1,p),f(o,p+1),f(o,p),f(o,p-1),f(o-1,p)],h=m[y[d]('')];if(h){t[o][p]=h}}}t=t.map(function(x) x[d](''))[d]('\n');return t;}
N.B. I've assumed that the first two input lines are actually irrelevant and the size of the following lines are a correct. I'm also reckoning I might be able to chop a few more chars off this when I get a chance!