6 kyu
Split Strings
54,909 of 165,458jhoffner
Loading description...
Regular Expressions
Strings
Algorithms
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.
hi everyone, i'm new to coding, and i'm stuck on this kata. I've tried slicing, appending, performing inplace modifications and for some reason i cannot manage to get an underscore added to the last index of an odd number of string. Can anyone give me advice or know how i can fix this problem. I'm really close to solving it, the underscore just always appears as a different index instead of being included in the last existing one already.
It is difficult to tell why your code does not work without knowing your code.
Also remember that you can always visit
#help-solve
channel on Codewars Discord and ask there!This comment has been hidden.
Your solution is not correct, it got one small thing wrong. See if this paragraph helps: https://docs.codewars.com/training/training-example#writing-a-solution
It is not a kata issue, you have to fix your solution.
Is there a specific method we should use? All logs seem same as answer, but the test said they were all wrong
This comment has been hidden.
This comment has been hidden.
But why is this an issue? Your code seems to incorrectly handle inputs of even length. Your solution falling into an infinite loop is not a kata issue.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
i hochu piccy rebyata
good problem for practice
Why did no one account for multibyte strings? Poor form?
I did the task like this:
Not a kata suggestion
this one was very very hard! its impressive to see how much better everyone is able to do these :P
Nice one
This comment has been hidden.
Kotlin translation
Approved.
I know this point is not mentioned in Question, but will handle the case if in the input string we have spaces i,e("never give up") ?
There may or may not be tests for spaces, but your code should handle any characters. If your code can't handle spaces, then you're on the wrong track.
In C++ gives error message "split_strings -> empty_string" which, what I thought, means that my code's answers are wrong meanwhile in all tests I did, empty string returns empty string which should be the correct answer.
the error comes from your code, it contains undefined behavior if the input is an empty string. your code generates several warnings, one of them should have put you on the right track:
std::string.size()
returns asize_t
, which is an unsigned number. think about what happend when you dosize - 1
whilesize
is0
.This comment has been hidden.
the testing code should be moved from preloaded to tests in C++
in Java,
assertArrayEquals
should be used instead of stringifying the arrays, which produces confusing assertion messagesFixed in this fork
approved
i'm assuming the test cases are incorrect? (ruby)
Why would you assume that? If test cases were wrong, the kata wouldn't be approved. The problem comes from the fact that:
1: you're mutating the input string (rarely a good idea)
2: the tests do not guard against this. First, your function is run with the mentioned string, which you mutate, and then the reference solution is run with what's left of the string, leading to unexpected results.
#2 is actually an issue, and should be fixed. I already see some issues raised below about it, and I'm amazed that this issue hasn't been fixed for 4 years or something?!
Still, I have to close it as duplicate (for now). Try to avoid mutating input where possible.
This comment has been hidden.
This comment has been hidden.
The problem is you're trying access a string by index, but using a negative index, which is not possible.
When you make such a change, the error message you get changes because a different test is being affected.
(if length is 5, then length - 1 == 4 ... index within bounds)
(if length is 0, then length - 1 == -1 ... index out of bounds)
This comment has been hidden.
You are passing a negative value into
charAt()
in this line of code....so it is going to crash for sure if you keep doing that
This comment has been hidden.
it's less than zero
Sorry bro but this is not helping if you can explain how is the value becoming less than 0 i will appreciate it otherwise thank you for your assistance
you can stare at your code and think about what it means, you can use print statements to see what that value is at any point, but it's up to you, and you should be able to figure out how you have given your variable its value
Yea you are right thank you bro.
This comment has been hidden.
This comment has been hidden.
That's why we have the Solutions tab. There's no need to post it here, where users haven't solved it, and can't see it.
A thousand apologies. I didn't realise I had to post elsewhere. Assumed that my post would directly go to the solutions tab since I've completed the exercise. Thank you for letting me know
This comment has been hidden.
Please use English on this website. Use a translator, if you have to.
There are some mistakes here:
This is not a kata issue, but a question. The tests are OK.
See https://docs.codewars.com/training/troubleshooting
Also, please format your code when posting here.
See https://docs.codewars.com/references/markdown/#code-block for an example.
This comment has been hidden.
This comment has been hidden.
Spend more time solving 8/7 KYU katas to learn methods that will make your life easier. (You don't need a for loop here)
anyone got any idea how they would use itertools to solve this? btw for python 3.10 pls
This comment has been hidden.
Code ran with warning on local and online compiler with Clang++8.0.1 (was Clang++ freaks out), but that was enough to be treated by Codewars as an error:
In file included from main.cpp:6: ./solution.cpp:16:7: warning: variable 'i' is incremented both in the loop header and in the loop body [-Wfor-loop-analysis] i++; ^ ./solution.cpp:12:35: note: incremented here for (int i = 0; i < s.size(); i++) { ^ ./solution.cpp:12:23: warning: comparison of integers of different signs: 'int' and 'std::__cxx11::basic_string<char, std::char_traits, std::allocator >::size_type' (aka 'unsigned long') [-Wsign-compare] for (int i = 0; i < s.size(); i++) { ~ ^ ~~~~~~~~ 2 warnings generated. /tmp/main-1368cb.o: In function
do_test(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)': main.cpp:(.text+0x15): undefined reference to
solution(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)' clang: error: linker command failed with exit code 1 (use -v to see invocation)sorry is that a problem with the kata or your own code? what are you saying that the kata should do differently? all I see from your post is that you point out a problem with your own code.
also, when you say "treated as error" I do wonder if you mean that it's showing you stderr, as opposed to refusing to compile, because your output says warning, not error, and if I produce warnings in the c++ env here then it does not treat that as an error - which is to say that it displays it but still compiles
the error comes from your code, you removed the
const
qualifier from the input (std::string &s
instead ofconst std::string &s
). As a result, the tests cannot find your function. this is a linker error, unrelated to the warning for comparison of signed and unsigned integers.This comment has been hidden.
Because you're printing the result instead of returning it.
This comment has been hidden.
Please don't post solution in discourse. Also, not a kata suggestion
This comment has been hidden.
That's a problem with your code, not a kata issue, print the input to help you debug your code and read the docs (like MDN) about the methods you use.
This comment has been hidden.
Please mark your post as having spoiler content next time. What's the kata issue there?
your code being too long is not a kata issue
why do we have to return an empty array if no string is given?
Writing in C++, i got an error on tests:
This error messages are invalid. Even if my code was wrong, it's not possible to send an array/string without closing symbols : quote and brace.
Unfortunately, this is something what can happen in C++ and it's not easy to do anything aobut this. Your solution has a bug, and at some place it puts
\0
into some of the pieces. Later, the failure message is build, the\0
gets in a middle of it, and when printed, everything beyond the zero character gets cut off.In your example, your first chunk is
"a\0"
, and when it is used as a part of the failure message, the message is not printed fully because the\0
is considered he end of the string.I can see how it is a problem, but it is not a bug in the kata, and it's not something what can be fixed very easily. Unfortunately, some low-level languages are like that, and C and C++ are the most common offenders in this regard.
if it's considered (past) the end of the string, then why is it included in the error output?
https://github.com/banditcpp/snowhouse/issues/40
https://github.com/banditcpp/snowhouse/blob/8db10c8114e520ed4ee05dea850d671b32af049c/include/snowhouse/stringize.h#L90C36-L90C36
if someone made a pull request to snowhouse to encode strings better, they might just accept that and then it would apply to all cpp kata
This is true in general, that
\0
being a part of the string should be treated as such, and ideally the printing could be fixed in the framework. But for this specific issue, the direct cause is an out-of-bounds read, because OP reads frominputstr[-1]
what is UB and kind of voids pretty much any other reasoning. Even if the message was not cut off and embedded\0
's were encoded and dispalyed by the framework, there is still no guarantee what it would actually be in the OP's case.Hello, the issue was in my code, that i tried to access an element on an index that is more than
std::string.size()
, which put'\0'
in somewhere else in the variable.This comment has been hidden.
your solution is not robust because it uses a space separator that it then splits on to produce the pairs. that's assuming that the input string never contains spaces, which is not true in the random tests. not a kata issue.
python new test frame work
Approved
This comment has been hidden.
look like? lists don't look like anything, they're data, not text. if you're asking whether you're printing the right thing, then it doesn't matter what you print because that's not how your code can submit its response
On Codewars, your function needs to
return
the result. You can print stuff to the console for debugging, but it will be ignored by the tests.I'm not very sure that I understood correctly and in some reasons I can't see your Solution huh. Very worthless huh. But. Maybe you mean that you wasn't use arrays? Because Im using IDEA for writing my code, and System.out.println gets me exactly [ab, cd, fg, h_]. Because its Array, you know. But if you used only String, it will be putting all together
In c++ when using to add the "" to an odd length if(l%2 == 1) temp += ""; split.push_back(temp);
the output doesn't reflect the concatination, tested it in vs code and the output matched, not sure what is happening
I've forgotten how tricky basic Java tasks are. It took many attempts of going back and forth, trying to understand why it would not recognize the last pair and add the underscore. Good test. Enjoyable once you solve it.
Weird test error expected [ 'ab', 'cd', 'ef', 'f_' ] to deeply equal [ 'ab', 'cd', 'ef' ]
You returned the wrong result (returned ['ab', 'cd', 'ef', 'f_'] when it wanted ['ab', 'cd', 'ef']).
This comment has been hidden.
OP solved it, closing
This comment has been hidden.
Your code fails with tests like this one:
Not a kata issue.
hello, this is not accepting single quotes, always putting a slash in front, can anyone help me?
This comment has been hidden.
.
Is something wrong with tests on this one? My code works perfectly fine when i run it in VS Code but it shows only errors when i run tests here
Without taking apart your code any further, please know that functions can return values (instead of just print them), and that is expected here. Any outside platform for coding a challenge may differ in other ways, such as not having the same tests. So, generally, do not rely on them to perfectly match the expectations of this site. The tests you find here will be the final gateway to success. More colloquially, "But it works on my machine" is not going to get you very far. ;) Best of luck fixing your code, enjoy the site, and much happy coding.
nice kata :)
Another Kata that works perfectly on VS code and XAMPP and fail TEST/ATTEMPT here...i Wrote this code three times and yet, it works locally but is not accepted on this platform...
In what language?
Your solution returns wrong answer for this test:
$this->assertSame([], solution(""));
The kata is OK, your code is not correct. Maybe this was the same for other kata too.
In Java, I think the testing criteria are off for the odd strings.
"Should handle odd string expected:<[ab, [cd, ]e_]> but was:<[ab, []e_]>"
I think the brackets are breaking it, and I couldn't get my code to read the expected output, because it would wind up as "[ab, [c, d], e_]" even if it took the brackets into account. Am I messing up though?
The brackets highlight the difference between both results, that's from JUnit, and they're not part of neither of those values. Your code is failing the first assertion in testOddString tests, not a kata issue. This test:
You can see there that for
"abcde"
should be["ab", "cd", "e_"]
exactly like the last example in the description.Ooohhhh my mistake. Thank you very much for the clarification there.
First rate coding exercise
I'm using ruby and when I click on attempt, the 100 random tests can never be fulfilled.
First, it will return an error saying it was expecting an empty array on a random string.
The exercise shows that when a string isn't empty, it should split it normally and return an array with the characters.
If you instead make that so only the example strings pass and every other random string returns an empty array (as it seemed that the attempt required), it shows a completely different scenario, where it expects the code to run normally.
So you can never have the 100 random attempts to work.
Tests are buggy and they fail when you mutate the input string. Your solution would work if you would not mutate the
str
.Tests need to be fixed so they dont fail in an obscure way when a user solution mutates the input.
.
it was cool, its been a while since the last time i used window funciton.
In golang the tests are wrong:
Expected <[]string | len:6, cap:8>: ["a", "b", "b", "c", "c", ""] to equal <[]string | len:2, cap:2>: ["ab", "c"]
No, your code is wrong, what's the input? Please read this before creating a kata issue: https://docs.codewars.com/training/troubleshooting/
This comment has been hidden.
If your regex doesn't match anything, it returns
null
, and you then try to use.map
on it (so you get this error).This comment has been hidden.
There seems to be a mistake in random tests when you hit "Attempt"
No, there is no problem in random tests in javascript. That's your code's problem, read this: https://docs.codewars.com/training/troubleshooting/
When I press "Test", it returns "You have passed all of the tests! :)".
However, when I press "Attempt", it returns an error in Random tests.
Take a close look at the expected results of any random test:
expected
[ 'Mn', 'Wc', 'kU', 'Xp', 'yw', 'fx', 'Uf', 'qp', 'F_', 'FH', 'vX', 'DU', 'Py', 'HI', 'DT', 'jO' ]
to deeply equal
[ 'Mn', 'Wc', 'kU', 'Xp', 'yw', 'fx', 'Uf', 'qp', 'FM', 'FH', 'vX', 'DU', 'Py', 'HI', 'DT', 'jO' ]
If you say there's no problem in random tests, how come 'F_' is supposed to equal 'FM'?!
That's a problem with your code. Print the input and debug it. Or add this test to sample tests and see your code fail:
There is no problem with the tests:
Sorry, my bad. Figured it out. Cheers.
This comment has been hidden.
(Ruby)
I had an issue with the random tests. It seem to expect "__" on even numbers of characters
Test Passed: Value == ["pX", "yg", "mY", "vO", "zr", "gm", "wC", "Yb", "U_"]
Expected: ["SH", "Kt", "rj", "QZ", "Lb", "QJ", "yd", "Ma", "La", "__"] instead got: ["SH", "Kt", "rj", "QZ", "Lb", "QJ", "yd", "Ma", "La"]
You are mutating the string, adding a _ and then the expected value is wrong. Your if condition is wrong.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Why if the string is "asdfadsf" the output shows: None should equal ['as', 'df', 'ad', 'sf'] ?
Read this: https://docs.codewars.com/training/troubleshooting/#expected-the-same
Hi @codesilas and welcome to Codewars - it seems this is your first kata: on Codewars you must return your final result, rather than just
print
it to console.So replace your current
print(new_list)
with the return statement:return new_list
. That's why the tests are sayingNone should equal ['as', 'df', 'ad', 'sf']
-- this error message means that you are not returning anything, hence theNone
, while the tests are expecting the list['as', 'df', 'ad', 'sf']
.I recommend reading https://docs.codewars.com/getting-started/solving-kata and also this Troubleshooting guide as you start out with the site, as Chrono79 said - it contains lots of helpful info.
(Javascript)
The first time I solved this kata, there was a strange sample test that may be some sort of error.
The test was for input "C". Output was ["ab", "cd", "ef", "g_"]
I wrote a if statement that returned that output for input "C", and it passed.
I went back to the kata just now so I could copy the sample test and list it here, but now the sample test isn't there. Not sure how this happened or how rare it is, but I figured it's worth mentioning.
Otherwise, thanks for the fun kata.
Probably you edited the sample tests. Not a kata issue.
These are the current sample tests. There is no input
"C"
there.In C++, my code makes use of size() in the algorithm's iterations' comparisons, push_back() to append to vector and substr to iterate through given string indexes.
All test cases work, and more test cases work as well, appending the character "_" to uneven strings.
The compiler returns:
'''In file included from main.cpp:6: ./solution.cpp:14:23: warning: comparison of integers of different signs: 'long' and 'std::__cxx11::basic_string<char, std::char_traits, std::allocator >::size_type' (aka 'unsigned long') [-Wsign-compare] for (long int x=0; x < original_string.size(); ++++x){ '''
I suggest you fix your site to support modern versions of the language.
How would " fix your site to support modern versions of the language" help in this case? Are comparisons of mixed signs OK in "modern versions of the language"?
My code works fine in local terminal by running g++ -o test test.cpp.
it should read:
for (int x=0; x < original_string.size(); ++++x){ (not like in the original post which I can't edit).
I should have added that in the first post, sorry.
G++ version is:
g++ (Debian 12.2.0-3) 12.2.0
And so by taking "using namespace std;" out and appending the std namespace to everything the code works.
What an incredible waste of time. Also no methods like += "_" or append or push_back worked, just had to re-assign the const by:
creating a string (oh, sorry, std::string for codewars) and using str.assign(s) (the original variable in the stupidly created function, by whoever the dim-witted author is).
I was recommended this site...I am starting to regret it...
Can you show code which "did not work"? The one with
using namespace std;
and+=
?Additionally, a word of advice: I would strongly recommend reconsidering the attitude of "this shit does not work WTF" and acting all butthurt over something what may, or may not, be mistake of the platform just as well as your own. It's difficult to know what exactly caused your problems because you provided no code, but:
x
is signed andsize()
is unsigned, compiler is allowed to raise a warning since this mistake can lead to bugs. You need to fix the comparison to use the same signedness for both operand, for example by changingint x
tosize_t x
.std::
from your solution an addedusing namespace std;
to it, and had no problems.s += "_";
and it did not compile due tos
beingconst
, it's not fault of tests nor of "dim-witted" author, because it's a normal C++ practice to pass arguments which are not expected to change asconst&
. To solve the task it's not necessary to modifys
, and if you want to modify it, you have to take care of it yourself. passings
as aconst string&
is actually a correct design decision, and changing it to non-const is unnecessary.I am going to resolve this stupidly raised issue as a user error. If I managed to guess your issues right, they are mostly a problem with user solution, and "fix[ing] your site to support modern versions of the language" will not help. If I did not guess your problems correctly, feel free to reraise the issue, providing actual details of what is wrong, what does not work, and why you think it should work.
Pretty lost here with what's wrong. New to the site and I've passed the test, but when I hit attempt it says that I've failed one random test. Can anyone help here.
expected [ 'UI', 'Dz', 'Eu', 'Og', 'rs', 'u_', 'mG', 'Uk', 'sw', 'qZ', 'kM', 'u_' ] to deeply equal [ 'UI', 'Dz', 'Eu', 'Og', 'rs', 'uU', 'mG', 'Uk', 'sw', 'qZ', 'kM', 'u_' ]
Looks like in the expected you have a string that reads 'u_' and it's supposed to read out to 'uU', without eyes on the code it's hard to tell why but it seems like you're getting that string 'u_' twice in your solution array.
NameError: name 'solution' is not defined
I keep getting this error 👆👆👆. I'd like to know why
Because you need to write a function called solution, check the initial code:
Replace
pass
with your code, read this: https://docs.codewars.com/getting-started/solving-kataIt's solved. Thanks
/tmp/main-a218bf.o: In function
do_test(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)': main.cpp:(.text+0x15): undefined reference to
solution(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)' clang: error: linker command failed with exit code 1 (use -v to see invocation)get this error... have no idea what to do... hewp me (^-_-^) checked my solution in VStudio and everything is working perfectly fine
You changed the signature of the function. Now linker cannot find it.
It's an error in your code, not a kata issue.
tank u. Solved! My stupid ass didnt know how pointers worked (and my understanding about then is also very limited) as i started with c#. hehe
Just passed in Python, thanks for this kata
This comment has been hidden.
This comment has been hidden.
Approved
This comment has been hidden.
This comment has been hidden.
OP solved it, closing
Update to Scala 3
.
Who can explain me this error:
expected [ 'HK', 'KL', 'MU', 'VY', 'ab', 'eg', 'jn', 'no', 'pq', 'tv' ] to deeply equal [ 'Mq', 'Kb', 'aj', 'pV', 'nv', 'Kg', 'Yn', 'Uo', 'He', 'Lt' ]
My function return [ 'HK', 'KL', 'MU', 'VY', 'ab', 'eg', 'jn', 'no', 'pq', 'tv' ] and I think it's right because it's normal sort by alphabet.
I don't understand how we can get [ 'Mq', 'Kb', 'aj', 'pV', 'nv', 'Kg', 'Yn', 'Uo', 'He', 'Lt' ] when we sort by alphabet
Why are you sorting them? You're not supposed to do that.
Lua translation!
Honestly way too easy for 6.
This comment has been hidden.
This comment has been hidden.
Please don't use issue tag for problems with your code, read this: https://docs.codewars.com/training/troubleshooting/
This comment has been hidden.
is something wrong with the single quotes ? my code returns exactly the same array as the one expected but still fails the test
This comment has been hidden.
Print the input, read what the methods you use return. Mark your post as having spoiler content next time.
i dont get what u say, i've did same test in VS Code and it worked okay.
Your code is returning null for some input value, change your code to return what is expected in that case. In VS Code you didn't use that input value to test your function.
nice exercise :)!
Got this fun error from a do/while loop 'UndefinedBehaviorSanitizer: nested bug in the same thread, aborting.' Switched it to while loop and it passed.
Does anyone know why it doesn't pass the test? Test Results: Example Tests Log ['as', 'df', 'ad', 'sf'] None should equal ['as', 'df', 'ad', 'sf']
None should equal...
means your code returnsNone
, in general it means it returns nothing. You need toreturn
the result, not print.This comment has been hidden.
I find out that's
replaceAll()
still not support :(Not available in Node v14, not a kata issue.
I see. Thanks
COBOL translation + description updated to be language agnostic according to official recomendations (it includes a codeblock for C with specific instructions, but there is no C translation currently available nor pending approval... However this note would fit better in solution set up).
Approved by someone
This comment has been hidden.
You are printing the result to console, when you should return it.
can u edit my code with the return statement? Would really appreciate it. Thanks!
What? No :D It's your code. Just replace every
print_r
withreturn
.This comment has been hidden.
Not a kata issue, read this: https://docs.codewars.com/training/troubleshooting a problem with your code is not a kata issue. You're not always returning the array.
This comment has been hidden.
Yes, you are completely right. There are no issues in the kata. Kudos to you for attention:)
This comment has been hidden.
This is an easy task. You should just read the description again and have a look at the examples.
This comment has been hidden.
Not a kata issue, print the middle values, like
SB
. Also, what did you use it for? Check your code again.Thanks, SB stands for StringBuffer I used it to insert comma in every 2 characters inside the given string. If may I ask, what do you mean by printing the middle values?
Middle values, for instance SB. It's not right. And you return s, not SB.
This comment has been hidden.
you don't take into account the case when
s=''
THANK YOU!
I totally missed that. Should have been more diligent looking through the test case code.
Thanks again.
This comment has been hidden.
You're not returning anything.
This comment has been hidden.
Please use a spoiler flag when you post code. And don't post twice for the same thing.
This comment has been hidden.
This comment has been hidden.
Could you post the code here, that you tried solving with?
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
You have to understand a bit how codewars works. It doesn't work with reading inputs from console or writing them there. When you enter the editor you should see initial code like this:
And your job is to complete that function and return (not print) the result. Use the given argument
str
instead of taking inputs. There are tests that will check if your function works like it should.Is that clear enough?
Ah, so you know how it works. I ran your code for sample tests and got:
This tells you a lot of information. In short:
You can use
Console.WriteLine
to check what input (str) is used, and also use it for debugging. You can see a few sample tests on bottom right of the screen.yeah srry I replied to my comment with what I had actually put in cw editor. The first reply is what i had in vs. This was my bad. Your reply makes sense, thanks for the help!
You don't have to mark every post with spoiler flag, if that post doesn't contain solution information :P
Anyway, I guess the question is resolved for now, but you can still reply here if something is still not clear.
This comment has been hidden.
You should start by reading the error, and if you can't understand what it means, post the error here.
Also, you can not try all test cases locally, just the basic tests. This may help: https://docs.codewars.com/training/troubleshooting/
I am having exactly the same problem. It works perfectly fine on my editor, but here it doesn't work
Please go read the troubleshooting section and come back with some proof your code works.
This comment has been hidden.
Your functions should return an array of strings with two chars, see the examples in the description.
This comment has been hidden.
Not a kata issue, read this: https://docs.codewars.com/training/troubleshooting#expected-the-same
This comment has been hidden.
not a kata issue
i have returned empty value if the input is empty in array but still error like this : null does not match expected type "array".
Given the error message, you're returning
null
instead of an empty array.This comment has been hidden.
There is! Python is heavily documented as is Java, you just have to know where to look :)
Java: https://docs.oracle.com/en/java/
Python: https://docs.python.org/3/
Hope that helps some :)
I don't like this kata(JS). It's all about crazy examples of regular expressions. How do people come up with such? How long should you practice RegExp's to write them? It's just a 6 kyu, remember?
But this kata is not about regular expressions? I did not use any, it's not necessary.
Man... This is just confusing as hell. I've been programming with C++ for the past several months and this is the first english website I used and this question has me completely mistified. I never used anything like this, only the console on CodeBlocks to solve problems. At least this humbled me a bit, heh
Hi. Maybe you should begin with some very basic katas to get a bit more familiar with the interface. There are plenty of them :)
Everthing works on IDE with same data as full suite test. But is giving wrong output here for [].
IDE(Intellij) result: Enter a string: Hello[]World Result[He, ll, o[] , Wo, rl, d_]
Codewars testing window: Should handle Space in string expected:<[He, ll, o[] , Wo, rl, d_]> but was:<[He, ll, o[,] , Wo, rl, d_]>
Those
[]
aren't part of the input string, that's JUnit showing you where is the difference between one result and another.Please elaborte. Sorry, I am new here. When I am using Test button. The results are coming OK. But, on Attempt button, the result is changing.
The input string is
"Hello World"
."o "
is a pair in the expect result, and it isn't in your answer.This comment has been hidden.
You log the result, but do you also return it?
I understand my mistake, now I am trying to solve it.
This comment has been hidden.
That depends on the language, in javascript version, only letters are used.
Failed asserting that two arrays are equal.
Expected: Array ( )
Actual : Array ( 0 => ' ' )
Does anyone know what this means?
I tested my code in Visual Studio Code no problem, but when I tested it on the site this message appears.
Note: I used PHP 7.0
Please read this: https://docs.codewars.com/training/troubleshooting/
Your function returns an array with an empty string, and the expected value is an empty array.
This comment has been hidden.
This comment has been hidden.
Not a kata issue, please read this: https://docs.codewars.com/training/troubleshooting You're returning a vector with a single string, with double quotes and commas, and you should return a vector of strings, where each string has a length of 2.
This comment has been hidden.
Why are you using the function declaration to declare vars? Why don't you do it inside the function's body?
Please use markdown tags to format your code or it is very discomfortable to read: how-to-format-code-in-markdown.
This comment has been hidden.
Please see if the last bullet point of this paragraph helps: https://docs.codewars.com/training/troubleshooting#expected-the-same
Thank you!))
I have this error: IndexError: pop from empty list
I don't know what I did wrong because when I check this code in visual studio code there is no error
That's a problem with your code, not a kata issue. Read this: https://docs.codewars.com/training/troubleshooting/
The error message is very clear, you're trying to use pop on an empty list.
This comment has been hidden.
Not a kata issue. And don't post solutions in Discourse.
can someone explain to me what this error means:
Response received but no data was written to STDOUT or STDERR.
Is it possible that your solution crashes, or has an infinite loop? If not, it's possible it's a kata bug. What language is this? Can you share your code? (see here how: https://docs.codewars.com/training/troubleshooting#post-discourse)
Try resubmitting your solution or refresh the browser (seems like you've solved it ^^
This comment has been hidden.
Because you're printing the result, not returning (what you should do)
I tried returning. That produced even less results than printing. At least with printing I see every output matches their desired output. When I just return they still score 0, but show no output from me. This platform is screwed. I wanted to progress to harder problems, but not if every problem is going to say I am wrong when I am right.
If you're only printing, you're passing exactly 0 tests, I don't understand how you can reason otherwise.
You can still print, but you HAVE TO return the result for tests to receive your answer.
If your every output matched the desired output, you'd be passing the tests. Clearly that's not the case. Are you using any global variables? That could produce unexpected results.
What errors are you getting? Which assertions are you failing? Could you provide an example of what you see?
The platform is fine, you just need to learn how to use it.
Be descriptive with the problems you encounter, not using some vague "doesn't work" nonsense and downvoting people trying to help you. We can't see your code or what you see on your screen, so...
For general troubleshooting, this article is a good starting point to answer some of your questions: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
This comment has been hidden.
Because 'null' has no length, as it clearly says.
Your code failing is not a kata issue.
This comment has been hidden.
Please mark your post as having spoiler content next time, read this: https://docs.codewars.com/training/troubleshooting/#expected-the-same Your function should return its value, there is no
return
there.Should be 5kyu tbh
This comment has been hidden.
probably found an error when testing in C#. it is necessary instead of " Assert.AreEqual" use " CollectionAssert.AreEqual", so that it compares not the collection references, but the values themselves.
I have tried the code on my IDE (C++) and am getting correct output but while running the tests it keeps giving error: linker command failed with exit code 1 (use -v to see invocation).
I have these errors :
expected [ Array(15) ] to deeply equal [ Array(22) ] expected [ 'ts', 'ai', 'az', 'fu', 'yg', 'q' ] to deeply equal [ Array(10) ] expected [ 'bz', 'h', 'v', 'z' ] to deeply equal [ 'bz', 'Oh', 'EQ', 'Mv', 'Yz' ]
and I really don't understand what's happening because it's not what it is asked. Any clue someone ?
Your code is returning wrong values, check the last one. It seems you're ignoring uppercase letters.
I passed the test, but when i click attempt it gives the following error message:
UndefinedBehaviorSanitizer:DEADLYSIGNAL ==1==ERROR: UndefinedBehaviorSanitizer: stack-overflow on address 0x7ffd609bb000 (pc 0x000000425a69 bp 0x7ffd609ba310 sp 0x7ffd609ba300 T1) ==1==WARNING: invalid path to external symbolizer! ==1==WARNING: Failed to use and restart external symbolizer! #0 0x425a68 (/workspace/test+0x425a68) #1 0x4257ba (/workspace/test+0x4257ba) #2 0x4285eb (/workspace/test+0x4285eb) #3 0x426ebe (/workspace/test+0x426ebe) #4 0x4267fd (/workspace/test+0x4267fd) #5 0x4264eb (/workspace/test+0x4264eb) #6 0x42c035 (/workspace/test+0x42c035) #7 0x425cdd (/workspace/test+0x425cdd) #8 0x7f3be1df4bf6 (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6) #9 0x404879 (/workspace/test+0x404879)
==1==ABORTING
And this was in the "split_strings".
Closing as not a kata issue. All solutions I tried seem to still work, and tests look good. Your solution probably suffers from some stack overflow error, most probably caused by errorneous recursion (but it's difficult to tell without seeing the code).
This was a good challenge. I spent a little bit learning some regex for it.
good kata
This comment has been hidden.
This comment has been hidden.
not a kata issue
This comment has been hidden.
Not an issue, your solution is wrong.
Have you tried debugging your code? Your way of determining the character index is wrong.
Here is another red test : Expected : [ 'Uo', 'aC', 'Kq', 'ey', 'Lk', 'Eq', 'Pc', 'ap', 'ZV', 'Q_' ] Actual : [ 'Uo', 'aC', 'Kq', 'ey', 'Lk', 'Eq', 'Pc', 'aC', 'ZV', 'Q_' ]
How the hell my code can be able to change a 'p' into a 'C' ?! Makes no sens.
This comment has been hidden.
Read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
It looks like this might be a typo due to font rendering? The extra character is supposed to be an underscore, but you seem to be adding a hyphen.
Pull some strings if you have to.
I have some kind of strange bug in the testing process, i have the rigth answer but the test just keep failing. expected [ 'a', 'bc', 'de' ] to deeply equal [ 'ab', 'cd', 'ef' ].
The error message says otherwise. Not an issue.
This comment has been hidden.
There is no such thing as a null array, only
null
orempty array
. In the current context,str
will never benull
too, just an empty string, and output will be an empty array as expected. Sample and fixed tests already have such cases, so closing.This comment has been hidden.
This comment has been hidden.
All you're doing is printing the elements, but you need to return them in an array.
Thanks for the reply, so should i make an arraylist, add the elements to it and return the arraylist?
This comment has been hidden.
Your soluion crashes when tested against following test case:
do_test("", {});
Not a kata issue.
Thanks for replying! I couldn't tell from the error message what the problem was, but I see what caused that now.
Groovy translation kumited. Please review and approve. Thanks, suic
.
Rust translation kumited.
This comment has been hidden.
I got the right answer, but it still failed me :(
odd_length Expected: [ ab, cd, e_ ] Actual: [ ab, cd, e_ ]
Any trailing / leading whitespace?
I don't think so, I don't use whitespace at all in the solution so don't know how that could happen. 'Actual' shows no whitespace too
Try posting your code here as shown here and mark it as spoiler.
This comment has been hidden.
lol I can't see my own code because its marked spoiler and I haven;t submitted yet
Uhhh actually I don't know why that is :D I can't really see what dotest is doing, and C++ is weird. It worked for me when I moved adding
_
logic above, but I see solutions similar to yours, so IDK :/ok, no worries :D
Your solution has a bug, take a close look at the assetion message in test output panel. There is an invalid character between
e
and_
. It's a result of an off-by-one error in your solution.Unfortuntely, yes.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
If the string is empty, the result should be empty array too.
how can i do it in c++, how to return list in c++?
For c++, it's a bit different. Here's the initial code:
So you need to return
std::vector<std::string>
for c++.This comment has been hidden.
Two reasons:
solution
tossss
. In this kata you need to keep original name,solution
, because tests call your function like this."main.cpp:11:16: runtime error: execution reached the end of a value-returning function without returning a value"
. It means that in some (all?) test your conditionif (i == fd.size()){
is not hit, and container is not returned correctly. You need to make sure that your function contains areturn
statement which is always executed.After fixing the function name and the issue with
return
, your solution works.This comment has been hidden.
This comment has been hidden.
Your code is wrong, read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
And also, the error message you get here:
It tells you what's wrong with your code.
This comment has been hidden.
Not a kata suggestion, a solution suggestion instead~~
Could'nt seem to get it working with php in anyway I tried.
Tried using my own solution and after givin up, unlocking solutions and trying the other solutions I still couldnt get it working.
Kept getting the error Failed asserting that two arrays are equal. when running tests.
Your code fails this test:
And the solutions you see there worked at some point, where that test didn't exist.
Invalidated those old solutions, not an issue anymore.
This comment has been hidden.
From here: https://docs.julialang.org/en/v1/base/iterators/
This comment has been hidden.
You're not supposed to post solution in the discourse section.
Sorry, I am very new on codewars. I didnt know about this
Works fine on my computer. But in browser always throws this error: "TypeError: solution is not a function".
https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
Just tested javascript (mention the language when reporting an issue) and works fine, the error points to a problem in your code, that we can't see.
Hi i need some help please, am splitting array but how can i add underscore at the and i tried with Array.fill and some other methods but wont work
Add underscore before splitting
dont get it still, how to add before splitting ? please if you can i need more details, thank you for comment tho
After splitting the whole string check if the length of the last element in the array is 1. If it is then all you have to do is join an underscore with the last element.
Yes i have done that long time ago but how to join that last element i tried with Arrays.copyOf to create another array , i tried with Arrays.fill and still couldn't finish
This comment has been hidden.
Please, don't post solutions in Discourse.
i am struggling with how the testin is done does anything need to be changed ??
Hi, i'm struggling with powershell. Passing all tests apart from 3 or 4 with same error.
Expected: value to be empty but it was { }
Please could someone point me in the right direction as to what i'm missing?
Thanks
same error for me for the 2 algorithmic employed
On my begin block I had the following code the following: if([string]::IsNullOrEmpty($string)){ Write-Output " Return i removed it and no more errors but don’t know if this was the cause or if it’s a fluke with random tests. I did try re-running them several times and the error did not appear, all tests passed. I tried using for statement but could not work out how to remove duplicates. I ended up with ‘ab’, ‘bc’, ‘ce’, ‘e_’ I decided to use if else statement instead, I spent all night on it. Even though I think it works I felt stupid and disheartened when I saw other people solutions. I’ll keep trying.
Output the same as the one requested, returned a vector of type string called result. Odd length tests don't pass, used INSERT() to add the _ character. Might that be the issue?
The test cases should add Unicode since that's an important consideration when dealing with strings, e.g. having the letter "ë" in the tests would break several implementations. See more here: https://mortoray.com/2013/11/27/the-string-type-is-broken/
Nobody's going to change the requirements now.
This comment has been hidden.
Hi,
Not an issue (more than 2000 completions in PHP, so the problem is in your code, not in the kata, hence, a "question", not an "issue" ;) ).
This means you're saturating the memory. I don't know PHP (except for its reputation... x) ) but I guess that like any other language, string concatenation is a pretty bad idea when the number of operations becomes huge.
Search for something around that.
cheers
I need help in this kata. My code isn´t return a array but i dont know where is the error. Please anybody may i help.
congratulations.
describe your problem, please.
This comment has been hidden.
Guys any help, am using if to test string length if its even than s.split ("(?<=\G..)"), and else spliting same way and creating new array input = Arrays.copyOf(input, input.length + 1); //create new array from old array and allocate one more element input[input.length -1] = ""; but am getting this one as a result as,da,a,, but i should return as,da,a_ any help please how to do that?
What are we supposed to in case of a
""
? I feel like that is what my mistake is, as I can't seem to understand what I did wrong...Later that day...messing around with the code...
solution "" = []
lol oopsC++ translation. Please review.
'alr approved some time ago'
Java translation. The original translation was by MartinPescatore. I added randomized tests, updated the description for Java/C/C++, and cleaned up the code some. Please review.
'alr approved some time ago'
All the Random Tests in Ruby expect nothing (
Expected: []
), but the random test do generate strings.I had the same issue.
Exact same problem.
I, as well as many others, had no issue, so that's you probably using bang methods or overriding built-in class. You should post your code with proper markdown and spoiler flag.
.
The String type in Julia can contain unicode characters. The unicde characters could be stored in more than one byte. So not all
str[i]
will be correct character because it could be a part of a unicode character.I suggest to add the test case:
This test case will fail if strings are splitted into bytes and not into characters.
Crystal solution is in global scope.
Actual and expected swapped in PHP.
Is it String split or both?
That is an example on how to write your own tests. You have to do it yourself or directly press submit.
Description is not clear
JavaScript version has no tests. Frustrating to discover that it can't be completed.
There are no sample tests, you have to write your own tests there if you want. There are test if you click on submit button and the kata can be completed:
This comment has been hidden.
Fixed
Clojure: there's effectively only 1 fixed test and 1 random test;
deftest
creates a global definition no matter where it occurs.This comment has been hidden.
there is no way to run the tests for golang version looks like there are no tests
I've added sample tests to the Go version.
I'll wait to let the change propagete. As for now I still see the same error (but I realized that codewars needs time sometimes ;) ) thanks!
No worries!
To see the changes:
Thanks! works (both: tests and my solution ;) )
This comment has been hidden.
Read MDN docs about matchAll it's available on Node 12. The highest available version for this kata is 8.1.3, use another way.
Php- keep getting this error. Parse error: syntax error, unexpected end of file in /home/codewarrior/run.php on line 23
That's a problem with your code, check if you didn't miss a closing
}
or something. I've just tested the php version and it worked just fine.This comment has been hidden.
Your function should return the result, not print it.
Thank you! Now it`s working!)
Julia translation
Scala translation available for review.
"solution did not return pairs with correct values" what can it mean, I passed all random tests except one, but in my test with even number of letters in string evrything work fine
hi, i solved this kata (kata told me to unlock), still, when i try to submit, it shows up under my own profile and solutions, but i'm told i have not resolved the kata and hence cannot view the solutions. trying to refactor the code won't work (bug in codewars), code 422. i may be still very new with python, but i'm confident my code works. (the tests were positive, too.) is there an issue with this specific kata, or did i miss any specifics so it doesn't get accepted in the end. (i removed the "pass" from my solution.") => ? any help appreciated!
Same here but my code is written in Javascript.
no sample test for js. You can just print return; and it works...
No tests included for JavaScript version. Can not complete exercise.
No sample tests, click Attempt or write your own.
Oh, thank you so much! I'm still new to CodeWars so I was pretty confused.
Test for JS: describe("solution", function(){ it("should test for something", function(){ Test.expect(solution("abc"), ['ab', 'c_']); Test.expect(solution("abcdef"), ['ab', 'cd', 'ef']); }); });
This comment has been hidden.
This comment has been hidden.
Hi guys,
It returns this after running "This is just an example of how you can write your own TDD tests - Expected: 'expected', instead got: 'actual'"
What does this mean?
That there are no sample tests, you have to write your own, or click attempt directly.
It's necessary to create test cases for this kata. It's not passing the last attempt for some reason.
This comment has been hidden.
Powershell version, once i wanta type "@" , all code will be gone
This comment has been hidden.
It doesn't work, because split doesn't convert the string to an array, it returns an array. It wouldn't work if you only fix that either, are you sure you have to use split there?
JS version doesn't have any tests, so it can not be completed at the moment.
Not exactly, it lacks sample tests (the author expects you to create your own), but there are tests on Attempt button (and the kata can be completed). The lack of sample tests is already mentioned below, no need to keep raising the same issue over and over. Closing this one.
JS tests should contain a comparison of what was expected and what was received when a test fails. Please also add sample tests for JS
done
PowerShell translation Kumited! :)
No samples for JS
There are no sample tests for Go.
Added.
CoffeeScript, Go, JS and Ruby versions need to be completely rewritten and with random tests added.
done
after 2 years
I've an error running tests for JS.
You're not providing any info that lets anyone else know what problem you're having, so as an "issue" it's a worthless comment. Resolving because it's utterly unactionable.
Also, unless you can prove that it's the kata's fault (hint: "I can't pass the kata with my 'working' code" is not one), it's a
question
, not anissue
.This comment has been hidden.
And Go too
Fixed
For JS: Write your own test in the panel below your script. It is a nice exercise. Hint: write a test for what the empty string should return.
Ruby version doesn't seem to actually be testing for anything.
This comment has been hidden.
Generally is not a good idea to change the array you're looping through.
i
is growing andletters.length
is decreasing. Not a kata issue (use question in cases like this), the problem is your code.Bad tests, horribly written. Should be revised or removed..
Descrition is fine. Tests are locked.
SMH, this Kata got me feeling some typa way
Bad test in Ruby , no information on failing whatever ..
I enjoyed the Kata, though I passed it fairly easily so I'm wondering if it was accurately labeled as a 6. Seems like maybe a 7kyu? Anyhow, I wish there were example tests for javascript, but I understand that I should learn how to write in my own. I think that is something I will work on figuring out next!
I can't see any tests for this in JavaScript. Though when I submit, it says 5 Tests Passed, and one failed, but the reason for the failure is super strange, it makes no sense.
What did not make sense? Which tests?
You know when a test fails it gives the reason back, right?
Why did you choose not to post the message out when posting a issue?
How would people be able to help you in this case?