5 kyu

Multidimensional Neighbourhood

Description:

I advise you to do some of the previous katas from the: Neighbourhood collection.


This is the next step. We are going multidimensional. You should build a function that return the neighbourhood of a cell within a matrix with the given distance and type. AND it should work for any dimension.

Input

  • type "moore" or "von_neumann"
  • matrix a N-dimensional matrix. N >= 0 (the matrix is always rectangular; could be a list or a tuple)
  • coordinates of the cell. It is a N-length tuple. Order of the indices: The first index should be applied for the outer/first matrix layer. The last index for the most inner/last layer. coordinates = (m, n, k) should be apllied like mat[m][n][k]
  • distance

Task

construct get_neighbourhood(n_type, matrix, coordinates, distance)

Ouput

The N dimension neighbours of the cell

Performance

Your code should be performant.

  • There will be two Tests with a very highdimensional matrix
  • There will be 30 Tests with 9 <= distance <= 12
  • There will be 200 Tests with N == 4, Dimension size == 5
  • There will be 30 Tests with N == 8, Dimension size == 3

Note: you should return an empty array if any of these conditions is true:

  • Index is outside the matrix (python: negative indexes are outside the matrix too)
  • Matrix is empty
  • Distance equals 0

Translations are appreciated.^^

If you like matrices chekout Array Hyperrectangularity

If you like puzzles chekout Rubik's cube

Algorithms
Logic
Data Structures
Arrays
Performance

Stats:

CreatedJul 12, 2018
PublishedJul 12, 2018
Warriors Trained340
Total Skips7
Total Code Submissions540
Total Times Completed38
Python Completions38
Total Stars16
% of votes with a positive feedback rating90% of 15
Total "Very Satisfied" Votes12
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes0
Total Rank Assessments3
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • sgerodes Avatar
  • Blind4Basics Avatar
Ad