exercism/julia/minesweeper/minesweeper.jl
2022-08-24 14:28:45 +02:00

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