Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
As a beginner-level kata plus the title having the switch keyword, the intro to
switch-case
usage is perfectly valid here. Though the usage of a lookup table or dictionary would be the ideal way of solving, users can refer to solution panel to view other solutions. OTOH, there exists other 8kyu katas which introduce techniques mentioned above, including what you've mentioned.A whole lot less code and a whole lot faster than my first solution :)
I think the reasoning for the first image is: if cell (1,2) and cell (2,2) are both part of the house, then that's a contiguous space, and the mouse is actually running across an open floor (which it's not allowed to do).
In the second image, the corners of two cells touch, so you have the same "crossroads" form that you could also get from intersecting line segments. Arriving at the crossroads, the mouse COULD politely turn left/right to define a contiguous area -- OR it could squeeze straight through the infinitely tiny corner, loop around the central square, and then cross its own path again. So that shape isn't permitted to exist in the house either.
It seems you didn't read the kata description:
Your solution is assuming that prime numbers can't be negative. But that's not your fault since the author is having the same problem.
The direction to use switch statements feels a little forced here. Since there's a 1:1 input/output relation, and the input is always an integer (starting from 0, in fact), an array of key/value pairs feels way more intuitive than writing out the full syntax of a switch statement. I think it's good not just to teach newcomers how to use certain approaches, but also how to identify the best one.
A more switch-suited problem might be one where the function has to behave differently based on the input's type, or based on the outcome when a certain operation is performed on it.
In the context of a function that can be expressed as a very short chain of basic methods, I think this syntax is fine and readable.
Obviously you wouldn't cram an extensive and complex function into this kind of one-line solution, but all THIS function needs to do is apply a few methods to a single argument and return it. Perfect use-case for shorthands if there ever was one. If we're worried about who else has to read and work with the code, giving each method its own line would resolve that well enough.