7 kyu
Indexed capitalization
3,329 of 10,612KenKamau
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.
JavaScript fork (kata author inactive)
This comment has been hidden.
The description indicates that out-of-bounds indices should be ignored. Your out-of-bounds
if
guard is misguided:This is checking whether
str[i]
is a nul byte. this will access memory that you should not be accessing, located in addresses beyondstr
. you have to check thati
is within the length ofstr
instead. the strange assertion messages you are seeing are due to you mutating memory that you are not supposed to.by the way, contrary to what the comment in your code implies,
strdup()
is available on Codewars. you just have to declare it somewhere withchar *stdup(const char *);
. this is becausestrdup()
requires C23, and codewars uses C18; butstrdup()
was available on POSIX and Windows long before C23.Liked it
Just solved in Go.
My solutions was assuming the array of indices was sorted based on the examples and it woked for all the solutions. I was also asuming the array contains no negative indices. But, reading the description, the assumptions were just not correct.
About the first assumption, I suggest to either ...
About the second assumption, I suggest to either ...
Nice kata.
This comment has been hidden.
This comment has been hidden.
Python fork with updated tests.
For Lua, when I fail the first test it says this:
"Expected objects to be the same.
Passed in: (string) 'aBCdeF'
Expected: (string) 'ABcdEf'"
The passed in value and expected value have switched places within the message.
Language: C++
Test suit missing the required headers
std::string/std::vector
.Python update (new testing framework)
Approved
Description is inaccurate; capitalization at indices outside the bounds require those indices to be ignored.
such a warm soulful kata! Thanks
Cool!!!...Little things)))...
In sample tests is one incorrect test
Test.assertDeepEquals(capitalize("bacdef",[1,2,5]),'aBCdeF');
JavaScriptthis must have been fixed at some point, or was a user error. the test case is now:
string = xopDjUdgHGJPoaUXWSAN
indices = {17, 4, 7, 45, 18, 9, 13, 14, 12, 4}
submitted = xopDJUdGHGJPOAUXWSAN
expected = xopDJUdGHGJPO
I tried this kata in C and one of the test cases fails.
"my code does not work" is not a valid kata issue.
Please read through this FAQ and see if it helps: https://docs.codewars.com/training/troubleshooting
Well my ouptput is correct and the expected output is wrong so I guess that counts as an "issue"
Hi @KenKamau, I've just noticed that mutating
ind
array will cause to fail at random tests (at least solving with Python). I think description should include information about mutating the input. If it doesn't I assumed I can do whatever I want with input. Apparently my assumption was wrong and my solution failed at random tests. Please consider changing one of the following:Aparat from that the kata is great. Cheers!
It looks like, there are some warnings in Kata:
main.cpp:33:29: warning: comparison of integers of different signs: 'int' and 'std::vector::size_type' (aka 'unsigned long') [-Wsign-compare] for (int i = 0; i < idxs.size(); ++i) ~ ^ ~~~~~~~~~~~ main.cpp:35:46: warning: comparison of integers of different signs: 'std::vector::size_type' (aka 'unsigned long') and '__gnu_cxx::__alloc_traits<std::allocator, int>::value_type' (aka 'int') [-Wsign-compare] if (idxs[i] < 0 || result.size() <= idxs[i]) ~~~~~~~~~~~~~ ^ ~~~~~~~ 2 warnings generated.
(it's not warnings from my code)
Error in Java, when i try to test the program it mark a false with no description with number 1. (I writed "System.out.println(s)" and the same in the end of the program to see where I make false, but everything is good. I check input and output in my program and in tests. They are same.
Unlikely. You could post the test case here and the result you are getting. Then I can check for you.
C Translation available
Approved. Many thanks. Keep them coming.
The Lua function is still broken, as mentioned by spudboy. It won't work unless you remove 'local' from the function.
My bad. Will edit.
Fixed. Let me know if aOK.
Fixed
Still not fixed
I have 106 correct submissions in Lua.
Does any of accepted submissions specifies function
indexcap.capitalize
as local, or all of them had to be fixed by users? Is fixing the non-compiling initial solution a part of the kata task?Have you checked, or are you just another fault finder? Please refresh and you will see that its fixed.
Well, actually, I've checked, but
local
was still there, also after refreshing. Now, after resetting the trainer, it's ok 👍This comment has been hidden.
Error running the tests in Lua - the solution template attempts to declare a local function inside a table:
Removing
local
fixes it.Also, Lua indexes from 1 by default. The sample solutions count the string positions from 0, which will probably trip a few people up. Could use a note in the description.
In Lua the function isn't exported to the tests properly by default because it's marked as local.
I disagree. Doesnt it work?
I had to manually fix it by removing the local on the function in the initial solution setup. Both of our solutions seem to have taken that "local" out, but it does indeed cause a compilation error if I open a new Lua solution and try to run it.
This comment has been hidden.
This comment has been hidden.
I'm happy it worked out.
Hi, Just tried to solve in C++ and found this in random test cases:
Test input "qesiaoxuqvz"; idxs = [87, 17, 88, 50, 67, 10, 16, 90, 31, 46]; Expected: equal to qesiaoxUQvZ Actual: qesiaoxuqvZ
10 is the lowest index and the only valid for this string. Why 'u', 'q' are capitalized? Bug in test or different rules (index "wraps")?
Not really an issue. We have 146 cpp completions. However, I've asked the translator to resolve.
Re-raise as question and include 5 failed cases. We have 146 successful cpp submissions.
Im having a similar result as szmodry
I guess that in my case issue was related to memory management. Bad code messed up part of memory where expected array was stored. My code was definitely buggy, but on the other hand tests should be robust against such issues, but this may be (?) limited in codewars' environment.
You should also state that array "arr" does not have to be sorted. P.S. Sort the array "arr" before you use it for solutions :) .
After 700 completions, is this necessary?
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Issues are for actual Kata problems, such as when the Kata is broken. This Kata has been solved 23x in C++.
You could start by understanding the error message you are getting, either by googling it or by asking for guidance here.
@gcohavy, what value is at "abcdef"[100]?
I don't get an error message. It just skips one or two capitalizations on the random tests
@souzooka as a general rule, toupper doesn't return anything if it doesn't exist. Also, one of the examples includes a [100, n] and it gets to the number after. I'm still a beginner so it is definitely possible that I'm wrong. But I sorted the vector at one point, and added: if(idxs[i] = false) break; and still got the same issue.
@souzooka. k so I got it to work, you were right. Just confused me that it worked in the sample. the =false thing doesn't work. Thanks for the help.
This comment has been hidden.
The description says the the two arrays may be of different lengths.
in which case what am i doing wrong? the prblem is that on the longer strings it's skipping one of the indices and i just cant figure out why so I'm not getting an error, it just doesn't work on a select few examples. But again, it works in all the set examples, just nt in the randm tests. I am using C++, btw.
This comment has been hidden.
The two arrays are not necessarily the same length and that's why you are getting this error. I advise you to research this error; you will learn alot.
I hadn't notice that you had raised an issue on this. Issues are for problems in the Kata, and your problem is in the code you posted.
If you need assistance with your code, you could simply ask a question without raising an issue.
I get the same error and have no clue whats going on
This comment has been hidden.
I'm not familiar with C#, but I've asked the translator to respond to this.
@Jarch24, in the meantime, please check your code. There have been 29 completions in C# and no issue reported regarding out of bounds.
@KenKamau, Sorry , I fixed my code, it works fine. Thank You.
Just finished a Haskell translation. Feel free to approve.
Nice! Approved.
Does this have random tests? I see
but does this generate random tests such as the ones in the examples?
This comment has been hidden.
Many thanks. I have updated it.
Hi @KenKamau, I made a C++ translation for your consideration here.
Approved. Thanks.
If indices can't be negative then the type should be
std::string::value_type
or maybestd::size_t
. Even if there are,std::ptrdiff_d
would be better. The type beingint
suggests there're negative indices, so there should be such tests in this case...Passing vectors by a const reference in the initial solution would be better too.
Which language? C++?
Hi Unnamed, I've written a new fork taken your suggestions into account. I'm still trying to learn C++ myself so I appreciate your feedback.
Can u address the issue raised on cpp translation?
This comment has been hidden.
Looks good! Approved.
Didn't have any issue accessing this one. Can you get the other two approved? Still have issues accessing them.
Thanks.
An issue has been posted for C#. Can you look into it?
Should not it be equal to 'aBCdeF' ?
Thanks. I have updated the description. The test cases were correct.