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 have similar problem on python
If you obtain all words from
""
, you will have an empty list,""
is not included.Otherwise, the most frequent word in any string would be
""
(or would you suddenly change your logic for that? be consistent.)Looking through Haskell solutions, every single one includes a literal empty-list literal because that is nowhere to be found in the input itself.
It isn't possible to return the maximum word out of zero words. This is undefined. Don't test for it.
Attempting to obtain the maximum word out of no words is a bug.
This is some kind of javaism of pretending null is acceptable. It's not. Not in java either.
At most I would accept that, yes, the input is valid, but the output is undefined, so any response, including crashing, is valid.
(But I'd rather stick to that if the input has no defined output then the input is therefore not valid, it's wrong to expect a result for it)
What is the average word length of
""
?If there's a word in that, how many words are there then in
"tree"
? 1? 2? infinite?Or are we going for that words are separated by space, that the number of words in a string is the number of spaces plus one? ie that
" "
is two words andis three words
But now we run into the issue of not being able to represent an empty string, because there's always at least one word in it. It's like removing 0 from our counting system.
Adding a word to
""
now means that there are two words, and that it has to have a leading space:"" + "tree" -> " tree"
, or rather, it doesn't have a leading space at all because there's a word first which takes zero space (should we really recognize something that takes zero space as counting as a word? I think that sounds wrong. If something takes zero space then it is not there)Also, if I slice an empty string, and don't include anything, then just the same I would have a word in my result.
No, you're right it's not obvious. I tried to defend this point of view because it's not explicitely stated in the rules that you must have at least one word, but it's definitely not obvious.
1 - Which language? Most don't check that case, but the answer is that you should obviously answer the best scoring word, which is
""
2 - The description says
All inputs are valid
, namely a string containing only spaces and lowercase letters. There is no explicit specification on the number of words, so""
," "
and such are edge cases, not invalid inputs (It indeed contains only spaces and letters)It would help if you mentioned which language has this problem.
It would also help if you could determine what the actual argument was that's giving you trouble - but the problem might be in the generating of the random argument or the processing of it; in the first case you'll never getit of course.