Use CartesianIndices instead of handmade tuples
This commit is contained in:
parent
af6eae89dc
commit
1c82d1716a
1 changed files with 1 additions and 3 deletions
|
@ -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
|
||||||
[
|
[
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue