Skip to content

Retrieve neighbours #30

Description

@lauramcastro

I am using Matrex in the context of AoC for the second year now, and it is not the first time I am confronted with the need to get the neighbours of a given position in the matrix.

That is, given a valid position {x,y}, calculating the list of [{x-1, y-1}, {x-1, y}, {x-1, y+1}, {x, y-1}, {x, y+1}, {x+1, y-1}, {x+1, y}, {x+1, y+1}] (or a subset of this, including only valid points inside the bounds of the matrix, of course).

Would a PR implementing Matrex.neighbours/3 as

@spec neighbours(Matrix.t(), non_neg_integer(), non_neg_integer())

something that this project would be interested in? If so, I offer to implement such PR.

An alternative would be Matrex.neighbours/4,

@spec neighbours(Matrix.t(), non_neg_integer(), non_neg_integer(), boolean())

with an optional argument (default true) to consider the diagonals (or not).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions