6 kyu
2D Cellular Neighbourhood - Part 2
142 of 183sgerodes
Loading description...
Algorithms
Data Structures
Arrays
Matrix
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Python:
describe
/it
)fork fixing both
Approved
6 kyu? Hmmm... I spent 2 days to solve this, and still not elegant comparing to other solutions. I solved other 6 kyu katas less than an hour sometimes. Is it only me or do you also think that difficulties need some review?
sighs in repetitive question
JavaScript: random tests still contain errors in both neighbourhood types. @rekill has a potential fix below.
.
Python (at least): empty matrix
[]
is never tested, only[[]]
Perhaps updating the description is enough.
javascript:
tests are contradicting with each other... some want the middle included, some don't? also
surprised anyone has passed this in JS
read discuss in bottom | v
.
Either I have misunderstood this kata entirely, or there is some error in the random tests (I pass all the basic tests, though). For example, for the von Neumann case with coordinates = [3, 7], distance = 1, and
I get this:
I fixed the bug in random test like this:
const _random = Math.random; Math.random = () => _random() + 1;
Thank you! This fix helped me pass the rendom tests as well.
Bug in tests?
matrix = [ [ 100, 25, 59, 35, 22, 11, 42, 75, 99, 7 ], [ 35, 61, 76, 74, 72, 45, 31, 7, 70, 82 ], [ 46, 37, 30, 55, 14, 51, 18, 44, 6, 35 ], [ 41, 2, 34, 34, 43, 56, 13, 71, 44, 17 ], [ 1, 8, 61, 35, 19, 16, 66, 25, 4, 39 ], [ 9, 71, 49, 11, 49, 53, 50, 81, 86, 62 ], [ 97, 19, 87, 16, 15, 37, 95, 38, 37, 21 ], [ 2, 55, 49, 96, 88, 21, 79, 76, 60, 54 ], [ 75, 86, 98, 92, 91, 73, 75, 77, 100, 20 ], [ 96, 82, 49, 5, 49, 81, 60, 60, 51, 40 ] ];
get_neighbourhood("von_neumann", matrix, [ 5, 8 ], 1);
Expected: '[4]', instead got: '[37, 4, 62, 81]'
Why 4?
Could not reproduce your bug. Given your matrix, using my code the output is [4, 81, 62, 37]. What is correct.
Check your random tests. The error is there.
This also goes to every kata in the series: neighbourhood type only makes sense for distance
1
, for every other distance the only notation that makes sense is "metric norm", aka how distance is counted.In the case of Moore and Von Neumann metric, the former evaluates to the maximum distance along one dimension, while the latter evaluates to the sum of the distances along each dimension.
(Alternatively, they are just
L_infinity
andL_1
metric respectively.)(Also alternatively, metric can be extended to other forms like
L_2
(Pythagorean metric).)Can not understand what do you mean. If you mean that with distance > 1 its not neighbourhood, than we had this discussion before with Farekkusu.
Von neumann neigh can be extended with the Manhattan distance. https://en.wikipedia.org/wiki/Von_Neumann_neighborhood http://mathworld.wolfram.com/vonNeumannNeighborhood.html
Moore neigh uses the chebyshev distance. https://en.wikipedia.org/wiki/Chebyshev_distance http://mathworld.wolfram.com/MooreNeighborhood.html
Yes, but note that you didn't say at all how the distance is extended for all
distance > 1
. The way to think about it is "how many cells/tiles/whatever you need to traverse to reach point A to point B, given you can only travel to these neighbours per step", which is not exactly an intuitive thing, so I think it should get some explanations.The Wikipedia is linked in the second part of 2D where i introduce the distance. There is an explanation for the distance of Neumann. All next Katas linked the collection with the words like "For better understanding solve previous". So the distance is explained.
Also the preloaded testcases help.:)
This goes to every kata in the series: You did not mention what are the order of the coordinates.
e.g in these two 2D katas, you only said
m,n
in the table, but what does the coordinate mean?(m,n)
or(n,m)
? Does the coordinate(a,b,c,...)
meanmat[a][b][c]...
, ormat...[c][b][a]
?It also doesn't help that all your examples have the same
m
andn
.Changed in the whole series
Moore neighborhood != manhattan distance. Don't mix up different things.
And, of course, cells can't be called neighbors if the distance between them is
> 1
:they are called neighbors in cellular automata theory. please take a look: https://en.m.wikipedia.org/wiki/Von_Neumann_neighborhood
http://mathworld.wolfram.com/vonNeumannNeighborhood.html
Thats the usage of the Manhattan distance on the Neigbourhood.
please explain what do you mean under "moore != manhattan distance".
I have applied the distance on the cellular neighbourhood. It is used in this way in the theory of Automata.
Yeah, the second point is just me being an ass :P, but Moore neighborhood doesn't work the same way as manhattan distance:
The title of the kata is incorrect.
There is a reasonable point in your thought. I will rename it to radius or simply distance
Yep, Chebyshev distance would be correct, but IMO it's all unnecesssary.No, Manhattan distance applies only to Von Neumann neighborhood and chebyshev distance applies only to Moore neighborhood - remove it altogether. And you should specify in the title that this kata is a part of a series like2D Cellular Neighbourhood (advanced)
or2D Cellular Neighbourhood - Part 2
(these are only examples, think of something you'd like the most).Changed, please approve
You know, you shouldn't ask for approval, it's up to the power users' consideration...
Nevertheless, cleaned up the description and the fixture. You should never shadow the built-ins like you're doing with
type
.Sample tests expect function name to be
get_neighborhood
instead ofget_neighbourhood
changed