Use CartesianIndices instead of handmade tuples

This commit is contained in:
Dimitri Lozeve 2020-02-23 14:36:55 +01:00
parent af6eae89dc
commit 1c82d1716a

View file

@ -22,9 +22,7 @@ end
"Return the neighbours to be filled of the cell at the given index." "Return the neighbours to be filled of the cell at the given index."
function neighbours(garden::Matrix{Int}, idx::Int)::Vector{Int} function neighbours(garden::Matrix{Int}, idx::Int)::Vector{Int}
m, n = size(garden) m, n = size(garden)
j, i = divrem(idx - 1, m) i, j = Tuple(CartesianIndices(garden)[idx])
i += 1
j += 1
neighbourindices = [(i, j-1), (i, j+1), (i-1, j), (i+1, j)] neighbourindices = [(i, j-1), (i, j+1), (i-1, j), (i+1, j)]
# cells filled with 0 are not part of the garden # cells filled with 0 are not part of the garden
[ [