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.
I don't think this should be tagged as "fundamentals". Math and problem solving may be "fundamental" in some sense to programming, but fundamentals katas are about training with a language against the simplest possible problem that exercises the language skills. This means that they are primarily about practicing syntax, not problem solving or math.
This comment is hidden because it contains spoiler information about the solution
A numerical edge case is understandable, but this is a text formatting edge case. The lack of spaces in the string the test means you have to write a specific return case JUST to satisfy that requirement. It's not difficult or interesting, just "if count is this value, return this specific string." If the test were rewritten to say "0 = 0" instead of "0=0" it'd be better and correctly represent programatically dealing with the edge case where the count argument is zero.
If the intent really is to have a text formatting edge case... well, you can do that. It feels tacked-on and doesn't seem to match up with the spirit of the problem, especially considering how easy it is to solve. It's more of a "gotcha", as it's written now.
The requirements for cases of count<0 are trivial and don't add anything to the kata. Suggest making this a "positive only" kata.
As others have mentioned the "0=0" solution with no spaces is inconsistent with the other solutions.
Learned from top solution:
split() already exists. By default it splits a string into 'words' which are any series of strings separated by some form of whitespace.
#Fighting the last war!
Actually I'm not sure how the third solution works at all. It looks like it produces a 100% win rate in the case of 'rock' so it should fail every time. I tried forking the solution and running it but there seem to be issues with doing that - even when I fork my own working solutions I get errors trying to run them.
I see that your commentary is the more general (and more correct) version of the things I was observing in these cases. I'll come back to this for reference.
The Python "trueval if condition else falseval" seemed intuitively understandable when I first looked at it. But the longer I think about it, the quirkier it seems.
I guess I knew that you had to return "something that evaluates to a value", ie. an expression. I would have expected conditionals to not be an expression, but it looks like a sort of exception was made for it?
Learned some interesting things from the best solutions:
From https://www.codewars.com/kata/reviews/57e155dded4102075c000087/groups/57e19efe621bcafa9e0014c6
From https://www.codewars.com/kata/reviews/57e155dded4102075c000087/groups/57e2545ca396b333e20001c8
From https://www.codewars.com/kata/reviews/57e155dded4102075c000087/groups/57e247e1ec7d24785a0002df
Thanks! I'm checking the solutions that others have done for each problem, once I write my own code. The top solution for this problem includes both your suggestions. The ".join()" aspect of the solution also came up in the best solution to the previous problem I worked on.
I tried to use both "for char in s" and ".join()" when writing this solution, but I couldn't make them work with the knowledge in my head. If I can't write the function with the knowledge in my head, I'll write what I can for a solution. Then, I'll carefully review the best solution and work on similar problems, repeating until I can write the code from my head. This way I learn about features of the language, then I practice memorizing the syntax every time I write a solution.
Eventually the solutions that I write will improve. I find that refactoring the code after seeing a better solution does very little to make the knowledge of how to write the improved code stick in my head, as it never really enters working memory. I'm not sure if I should avoid refactoring completely, though. Maybe I should refactor, but only after some amount of time has passed.