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 }