Skip to main content
added code highlighting
Source Link
Cristian Lupascu
  • 8.7k
  • 2
  • 25
  • 52

Ruby 140

f=->s{
r=s.dup
l=s.index(?\n)+1
(0...s.size).map{|i|
s[i]<?0||r[i]=r[i]<?1??.:[i-1,i+1,i-l,i+l].map{|n|n<0??0:s[n]||?0}.max>r[i]??-:s[i]}
r}
f=->s{
r=s.dup
l=s.index(?\n)+1
(0...s.size).map{|i|
s[i]<?0||r[i]=r[i]<?1??.:[i-1,i+1,i-l,i+l].map{|n|n<0??0:s[n]||?0}.max>r[i]??-:s[i]}
r}

Nothing special; just iterate through the map and compare the current value with the value of the four neighbors.

Run it online with tests: http://ideone.com/AQkOSY

Ruby 140

f=->s{
r=s.dup
l=s.index(?\n)+1
(0...s.size).map{|i|
s[i]<?0||r[i]=r[i]<?1??.:[i-1,i+1,i-l,i+l].map{|n|n<0??0:s[n]||?0}.max>r[i]??-:s[i]}
r}

Nothing special; just iterate through the map and compare the current value with the value of the four neighbors.

Run it online with tests: http://ideone.com/AQkOSY

Ruby 140

f=->s{
r=s.dup
l=s.index(?\n)+1
(0...s.size).map{|i|
s[i]<?0||r[i]=r[i]<?1??.:[i-1,i+1,i-l,i+l].map{|n|n<0??0:s[n]||?0}.max>r[i]??-:s[i]}
r}

Nothing special; just iterate through the map and compare the current value with the value of the four neighbors.

Run it online with tests: http://ideone.com/AQkOSY

Source Link
Cristian Lupascu
  • 8.7k
  • 2
  • 25
  • 52

Ruby 140

f=->s{
r=s.dup
l=s.index(?\n)+1
(0...s.size).map{|i|
s[i]<?0||r[i]=r[i]<?1??.:[i-1,i+1,i-l,i+l].map{|n|n<0??0:s[n]||?0}.max>r[i]??-:s[i]}
r}

Nothing special; just iterate through the map and compare the current value with the value of the four neighbors.

Run it online with tests: http://ideone.com/AQkOSY