5 kyu
Multidimensional Neighbourhood
38sgerodes
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 likemat[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
Similar Kata:
Stats:
Created | Jul 12, 2018 |
Published | Jul 12, 2018 |
Warriors Trained | 340 |
Total Skips | 7 |
Total Code Submissions | 540 |
Total Times Completed | 38 |
Python Completions | 38 |
Total Stars | 16 |
% of votes with a positive feedback rating | 90% of 15 |
Total "Very Satisfied" Votes | 12 |
Total "Somewhat Satisfied" Votes | 3 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 3 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 7 kyu |