26 lines
809 B
Julia
26 lines
809 B
Julia
function annotate(field)
|
|
afield = []
|
|
for x ∈ 1:length(field)
|
|
line = ""
|
|
for y ∈ 1:length(field[x])
|
|
el = field[x][y]
|
|
if el == '*'
|
|
line = "$line$el"
|
|
continue
|
|
end
|
|
stars = 0
|
|
if x > 1
|
|
stars += count(c -> c == '*', field[x - 1][max(y - 1, 1):min(y + 1, length(field[x]))])
|
|
end
|
|
stars += count(c -> c == '*', field[x][max(y - 1, 1):min(y + 1, length(field[x]))])
|
|
if x < length(field)
|
|
stars += count(c -> c == '*', field[x + 1][max(y - 1, 1):min(y + 1, length(field[x]))])
|
|
end
|
|
ch = stars == 0 ? " " : "$stars"
|
|
line = "$line$ch"
|
|
end
|
|
append!(afield, [line])
|
|
end
|
|
afield
|
|
end
|