6 kyu
Split Without Loss
46 of 240narayanswa30663
Loading description...
Fundamentals
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.
Fancy kata, congratulations.
python new test framework is required. updated in this fork
Greetings
I have written two different solutions which both use a loop. No recursion. Both run fine in Visual Studio but both crash with memory problems in Codewars
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
I have tried both 'resetting' and changing the Node versions. I get the same errors
How do I proceed?
This is my output from Visual Code:
console.log(splitWithoutLoss("hello world!", " |"), ["hello ", "world!"]); console.log(splitWithoutLoss("hello world!", "o|rl"), ["hello wo", "rld!"]); console.log(splitWithoutLoss("hello world!", "ello| "), ["hello", " world!"]); console.log(splitWithoutLoss("hello world!", "hello wo|rld!"), [ "hello wo", "rld!", ]); console.log(splitWithoutLoss("hello world!", "h|ello world!"), [ "h", "ello world!", ]);
console.log(splitWithoutLoss("hello world! hello world!", " |"), [ "hello ", "world! ", "hello ", "world!", ]);
console.log(splitWithoutLoss("hello world! hello world!", "o|rl"), [ "hello wo", "rld! hello wo", "rld!", ]);
console.log(splitWithoutLoss("hello world! hello world!", "ello| "), [ "hello", " world! hello", " world!", ]);
console.log(splitWithoutLoss("hello world! hello world!", "hello wo|rld!"), [ "hello wo", "rld! hello wo", "rld!", ]);
console.log(splitWithoutLoss("hello hello hello", " | "), [ "hello ", " hello ", " hello", ]);
Which Produced:
[ 'hello ', 'world!' ] [ 'hello ', 'world!' ] [ 'hello wo', 'rld!' ] [ 'hello wo', 'rld!' ] [ 'hello', ' world!' ] [ 'hello', ' world!' ] [ 'hello wo', 'rld!' ] [ 'hello wo', 'rld!' ] [ 'h', 'ello world!' ] [ 'h', 'ello world!' ]
[ 'hello ', 'world! ', 'hello ', 'world!' ] [ 'hello ', 'world! ', 'hello ', 'world!' ]
[ 'hello wo', 'rld! hello wo', 'rld!' ] [ 'hello wo', 'rld! hello wo', 'rld!' ]
[ 'hello', ' world! hello', ' world!' ] [ 'hello', ' world! hello', ' world!' ]
[ 'hello wo', 'rld! hello wo', 'rld!' ] [ 'hello wo', 'rld! hello wo', 'rld!' ]
[ 'hello ', ' hello ', ' hello' ] [ 'hello ', ' hello ', ' hello' ]
This means you are using too much memory (you are probably building a gigantic array or something like this, or a part of your code keeps pushing value into something and never stops), and it is not a kata issue.
Advice: your
while
loop is probably the culprit. You are probably not testing your code with the same input in VSC as here. Please refer to the documentation: https://docs.codewars.com/training/troubleshooting/Thank you, akar-0
But as you can see I posted exactly the input so that you can see what I am using! All I did was change the 'test.assert...' string to 'console.log' That's it! And ran both programs which displayed the answers straightaway As you can see
I would gladly send you the source code of my solution so that you can see what I mean, if that helps!
I solved the kata in JavaScript, so I am able to see your code. Your code passes the first sample tests, but fails in some of the series
for example
I don't think it works fine in VSC either.
Aha! I understand now. Thank you
python 3.8/new test framework
What is the expected output for
split("aaa","|aa")
, and why?I think it should be
["a","aa"]
, not["aa","a"]
, and definitely not["aaa"]
.It is ["aaa"].
Why?
The first point "|aa" is matched in the string ("aaa") is at index 0.
I agree that it seems weird. But there are no overlaps, and the first match is the one that counts. Hope that clarifies it. Thanks!
Weird, but correct. Thank you!
I have some solutions to update. The random tests don't always catch this (but sometimes do); you might want to add a static test with an odd number of
a
s, and maybe clarify this in the description.Thanks for the input. Will do!
And... done! Added five static tests to both examples and full suite for all languages. Hope it's ok!
Also, I figured out where I was thinking differently. I was not matching if left would be an empty string. However, you have to match but throw away the result. (I think my reasoning is valid as well. It's just not what you specified. :D )
Your instructions state that we should remove any empty strings from our output, which I have done. However, around 20-30 of the random tests expect the output to include empty strings, therefore it is not possible to pass all tests.
For example:
Expected: ["y", "", " vnsha jol ecz dqy", "", " vnsha jol ecz dq"], instead got: ["y", " vnsha jol ecz dqy", " vnsha jol ecz dq"]
This comment has been hidden.
Hi! Thanks for the reply. I'm working in Ruby. Here are some of the tests that fail in the Random cases (note that the expected output includes empty strings ""):
str = "r ij tcnmr ij tcnm" and split_p = "|j t" Expected: ["r i", "", "j tcnmr i", "", "j tcnm"], instead got: ["r i", "j tcnmr i", "j tcnm"]
str = "u xgowdny z he u xgowdny z he " and split_p = "|ow" Expected: ["u xg", "", "owdny z he u xg", "", "owdny z he "], instead got: ["u xg", "owdny z he u xg", "owdny z he "]
str = "xdvp iqyntwgcbxdvp iqyntwgcb" and split_p = "|p " Expected: ["xdv", "", "p iqyntwgcbxdv", "", "p iqyntwgcb"], instead got: ["xdv", "p iqyntwgcbxdv", "p iqyntwgcb"]
That is very strange. The random test function returns the valid
["r i", "j tcnmr i", "j tcnm"]
for your first example, and don't have any empty strings for the rest. Could you please paste your code and mark it as a spoiler? Thanks!This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
I hope you managed to get it fixed! :)
It worked! Thank you so much for taking the time to help out. I will be sure to leave feedback on your kata. Despite my coding mistakes I enjoyed it :)
Overlapping occurrences (
"aaaa", "|aa"
) would be a nice edge case to have in the tests because it ruins some nice and simple solutions.I like it! Unfortunately, I feel like too many solutions have been submitted, and invalidating them would not really be fair. Sorry about it.
It's beta, invalidating everything is fair, 9 solutions is not many at all, correct (according to the current description) solutions won't be invalidated. If you still don't want to test on this kind of delimiters then it should be stated in the description and the random tests should be modified because they do generate such delimiters sometimes.
Sorry. In the example that you provided, what is the current answer and the answer that you expect?
It should be
["aa", "aa"]
while with the first solution that came to my mind it was["aa", "aa", "aa"]
and I didn't immediately notice that the solution was incorrect.Clarified in the description. Hope it's ok.
It was already clear, the problem is that there are no static tests for that, so some invalid solutions may be submitted.
I have added 5 static tests for that. Your 'incorrect' solution has been invalidated. Thanks for your help!
This comment has been hidden.
Ouch, good spot! Will fix soon
It should be fixed now :)
This comment has been hidden.
I've made a couple changes:
I hope it's okay. If not, do let me know and I will do my best to fix it. Thanks for your help!