Minesweeper by kinaba

y=0
(m=readlines).each{|l|
  0.upto(l.size-2){|x|
    if l[x]!=?*
      c=?0
      0.upto(8){|d|
        yy=y-1+(d%3)
        xx=x-1+(d/3)
        c+=1 if yy>=0 && m[yy] && m[yy][xx]==?*
      }
      l[x] = c
    end
  }
  y+=1
  puts l
}

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

download

return to the top page