6 kyu
Duplicate Encoder
20,736 of 233,006obnounce
Loading description...
Strings
Arrays
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.
This comment has been deleted.
This comment has been hidden.
Your code doesn't return anything.
copy all in my message ,after "Вот сам код :"
Or maybe just post the code using proper code formatting?
After copying all your code, the answer is still the same: your solution does not return anything.
idk why it doesnt retern anything ,cause when i wrote in on VS Code it worked
Maybe because there is no return keyword in your code at all?
console.log
andreturn
are different.What happens when you do this in your VS Code:
console.info('My solution returned: ' + duplicateEncode("din"))
oh ,understood. So ,if i change it to return ,will site approve task?
If the code is correct, then it will. Just try it.
This comment has been hidden.
Is this code bugged in Ruby? Running "test" only runs one test (which it passed). I had to manually check every listed test, which all match. But when I try to submit, it fails...something...
i added better assertion messages to Ruby. your code is wrong,
downcase
is not a mutating method, so think about how it affects the logic of your code. please do not raise issues so lightly in the future, ask a question instead to ask for helpOkay, i removed the "issue" flag and, though my biggest issue was that it produced errors referencing lines and code that had nothing to do with what I provided, i'll avoid the issues button. I'm new to this site so please let me know at what point it is advisable to touch the "issue" button.
Edit: also I'm not sure how to make sense of your comment.
"".downcase
is valid Ruby to run on a string and passes the initial test. Unless I am drastically mistaken here, I assumed that the arguments used in both the initial test and the tests used on submisssion would be strings.You are right that arguments are strings, but the way how you use
downcase
is not fully correct. How will your solution work for string"aA"
? What willword.count(l)
return for each character?The
Issue
tag is meant to be used when you find a bug or some other problem in a kata, and something needs to be fixed. In this case, your problems are caused by a bug in your solution. There is nothing to fix in the kata.This comment has been hidden.
Groovy Translation
Approved
This comment has been hidden.
the problem i am having is do i copy the sample test or do i create my own words and code?
When I first looked at it, I thought, "This one is really easy, I'll solve it quickly." ... ☠️
Good kata
This comment has been hidden.
Your solution returns the input word, but it should return the word after encoding.
Indeed. Thank you!
This comment has been hidden.
Yeah, sometimes diving right in isn't the right thing to do. Take your time and solve it carefully. You may even realise you don't even need to use a map.
random checks produce different results, sometimes ")" is ")", and sometimes "(", although they are not repeated.
This does not sound right. Can you show your code, and an example input which you think is handled incorrectly?
I'm writing in js and it's not clear to me what is required of me. I've refactored the code several times, but I get the same error when I try to
The
??
operator is not supported by the node version you're training in. Make sure you have node 18 selected or, if node 18 is not available, rewrite your code without using??
.It looks like you're using https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing which is only available since node 14. Are you sure that you have node 18 selected at the top?
Chai + assert for CoffeeScript
Someone know why does this happen:
should ignore case: '(())())' should equal ')())())'
Besides that test everything ok :)
This comment has been hidden.
This comment has been hidden.
Approved
wrong testing for lowercase regex, works in vsc but not here
"Is my code incorrect?"
"No, it is all twohundredthousand other solvers who are wrong."
This comment has been hidden.
it's hard to read your code because you didnt use code blocks so some characters got interpreted as formatting. That being said, it looks like you are creating a regexp dynamically without proper care. this might be of interest to you
Thanks for the help, i will check it out :)
nice little exercise. at least a couple of different ways to do it, and nothing tricky. looks like historically the tests might have needed some attention, but seem fine now (python)
Passed the basic_tests after 1-2h, now I'm stuck at randoms....
I don't know why fail,
[----] test.c:22: Assertion Failed [----]
[----] for string: "walk" [----] expected: "((((" [----] but got: "((((" [----]
[FAIL] duplicate_encoder_function::sample_tests: (0.00s)
maybe you have some unprintable garbage in your string. check its content.
Fun, but way too easy for 6 KYU..
I think they should remove the test with parantheses because parantheses are obviously no letters. My programm works fine but only for letters so....
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Test doesn't match the description.
Description: each character in the new string is "(" if that character appears only once in the original string, or ")" if that character appears more than once in the original string.
Test: Expected : )))))) to equal : )))))(
There are no chars in the original string that appear only once, any of ")" appear more then once, even the last one. There is no rule "more than once AFTER its position".
My solution passes all tests except this one because I use strings.ReplaceAll() for all duplicates in go lang.
Fix this test pls.
There is nothing to fix there, the first value in the error message is what your function returns, not the input. To see what the input is, print it.
This comment has been hidden.
Your code fails for cases like
recede
because your code returns((()()
whilst the correct output should be()()()
. Read this carefully -->or ")" if that character appears more than once in the original string
I'm not a pro but that is interesting
That's prety fun
I'm able to pass the sample cases, but the cases tested when I click "attempt" don't pass.
I try ending the string with the null character '\0', but when indexed at +1, it always prints one character extra. without the +1, it says the test cases failed.
Before I ended with the null character it just attached an arbitrary number of characters after the original string, but that I did sort out
This comment has been hidden.
See https://docs.codewars.com/training/troubleshooting/#print-input and https://docs.codewars.com/training/training-example#debugging-a-kata.
This comment has been hidden.
Array.prototype.toSpliced()
requires Node 20 and Codewars currently only supports up to Node 18.Not a kata issue. See https://docs.codewars.com/training/troubleshooting#post-discourse.
This comment has been hidden.
Please, do not raise issues so lightly. The problem comes from your code: you are inspecting uninitialized memory in
mystring
. Note thatmalloc()
does not initialize memory it gives you. In particular, whenmalloc()
returns memory with')'
(ASCII41
) bytes, your code will behave incorrectly at this line:This happens during the tests because the tests suite
free()
s your string, and then you happen to get back the same memory chunk at the next call tomalloc()
.I think the instructions are wrong. It says "you can ignore capitalization" and when i ignore capitalization, the word Supralapsarian fails, it says that the first 'S' is not repeated when it is if you follow the instruction and "ignore capitalization".
Enabling capatilization causes my tests to fail, disabling it causes tests to pass, but 'Attempts' to fail.
)
is for repeated letters, isn't it? The description and the tests are fine.Remember that Lower Case matters!!!
Looks there is a mustake in current KATA. My code in VSCode get different inouts between here in JavaScript.
The mistake is once again in your code, see which input makes your code fail and debug your code, please.
This comment has been hidden.
OP solved it, closing
Completed the solution in JavaScript
Once I understood the difference between the brackets in the output, it was a good challenge to beat.
Only feedback I can give is to add to the output explaination (whats below) the diffence between the brackets so it would make sense to new challengers faster.
"(" = Character that only appears once ")" = Character that only appears more than once
That's already in the instructions:
This comment has been hidden.
Please read Troubleshooting doc before creating an issue.
Your code is not 100% right and it'll fail when the string contains parentheses. Use
Question
label if you can't prove the problem is in the kata:Printing the input will help you to debug your code next time.
This comment has been hidden.
you renamed the function from
duplicate_encode
toduplicate_count
for some reason. Don't do that, the tests rely on the given name of the function. Only write the function body.pffff stupid mistake ... i made too much katas in 2 days, i'm losing my mind ! Thank you for your reply !
this kata non-correct work with replace (python)
Seems like there is a bug in this one, for Rust. Or the characters are using different encodings. In my case, the C in CodeWarrior is getting dropped but matches should find at least 1 of every letter. Then in Supralapsarian matches is returning three individual occurences of "s" instead of one group of three "s"'s. I don't know if you can see my code and what actually gets printed out using Rust matches?
Problems in your own code are not kata issues.
This comment has been hidden.
I feel like I'm missing something...
If a character shows up in a string more than once should be replaced with ')'
So shouldn't ')))(()())())' output as '))))))))))))' and not ''()(((())())' <~~~ what they are saying it should be?
You're most likely misinterpreting the assertion error messages. You're looking at the actual and the expected output, not the input. If the assertion error messages don't show you the input, you can print it yourself. See https://docs.codewars.com/training/training-example/#debugging-a-kata
[C++] I literally tried my code with the input case "Success" and it displays the correct output on my compiler. But on this website, when I run, it displays "(((c())" instead of ")())())"
Your solution has a bug, it sometimes calls
positions.front()
whenpositions
is empty.It's a bug in your solution, not a kata issue.
I'm new in CodeWars I'm having a problem in testing my solution it return: '( ( (' should equal '(((' '( ) ( ) ( )' should equal '()()()' should ignore case: ') ( ) ) ( ) )' should equal ')())())' ') ) ( (' should equal '))((' Even the result I get is correct.
You added space between parentheses in your result
This comment has been hidden.
Extremely satisfying kata for this level, have fun!
how does one solve this... damn makes my head hurt
This comment has been hidden.
Mark your post as having spoiler content next time.
OP solved it, closing
I have even know that 'S'=='s' until I pass this test haha they are not the same btw difference in ascii code for your programme as exemple in C language if an alphabet in input string is upper and the same character occure or repeated with lower cas it should be the same :)
does anyone know why I cant delete anytjing that I tyoe type throughout this website? it does it here in comments, I cant delete any misstyped chars.. but ecv even worse on my o code
None should equal '(((' None should equal '()()()' should ignore case: None should equal ')())())' None should equal '))((' Why? I have the result just the one that is required to pass. I don't understand, what need author
This means that your function returned
None
when it should have returned<value>
. Seems like you're printing instead of returning. Read this: https://docs.codewars.com/training/troubleshooting/#.print-vs-returnThis comment has been hidden.
I can't see your code, but I'm guessing that your function is not named appropriately (it should be
duplicate_encode
).EDIT: You updated your error. Please keep in mind that you're expected to solve katas mostly by yourself instead of asking for help each time you encounter a new error. Seeing you are a beginner and are having difficulty solving this one, I recommend skipping it for now and try easier katas instead (e.g. 8 kyu).
Also, consider joining the official Codewars discord server where there are dedicated channels to get help solving kata (e.g.
#help-solve
).but my code is work, and i have right results. and thx for the advice)
The argument of your function is a string, not a list of strings. See how it is called on the sample tests.
This comment has been hidden.
look up the solution on google but do not copy it or you wont learn. look up each method onm mdn and then give it a shot again with that knowledge
Is there a listing of what is included in the system for testing? I was getting an error that .Count is not available on character arrays in C# newest. This is a standard function and couldn't get the system accept the answer. If there is a listing so I can setup my testing environment close I would appreaciate it.
My solution passes all the fixed tests when I click on test but when I click attempt I get this message saying it failed:
should pass fixed tests Expected: "()(((())())", instead got: "))(()())())"
I don't understand. "Expected: "()(((())())"" isn't even in the fixed tests suite.
Also another 'random test' fails, it tells me the output is not what was expected but I cannot see what the input was from this random test.
You can see the inputs which cause your solution to fail. See here.
Also, sample tests, like the name suggests, are a sample of the full test suite (AKA submissions tests). As a solver, you only have access to the sample tests.
Thanks NunoOliveira but this is the entirety of the text in the Output window, I cannot see anything more than this, there is no indication of what the input is for those outputs:
Fixed tests should pass fixed tests Expected: "()(((())())", instead got: "))(()())())" Completed in 0.5487ms Tests with '(' and ')' Test Passed Completed in 0.2629ms Completed in 1.6801ms And now... some random tests ! should pass random tests Expected: ")))()))()()))))))))))())()()(", instead got: ")))()))()())))))))))))))()()(" Completed in 0.4715ms Completed in 0.6524ms
Did you read the excerpt I linked you? You need print the inputs (
puts
orprint
in ruby). I haven't solved this kata in ruby, so I can't see your code.Your conditons are just... wrong. Maybe you misunderstood the task, but I can tell that you're not handling case sensitivity correctly.
OK, sounds like I'll have to skip to the solution. Thought I was on the right track with my test cases all passing.
Thank you, B1ts. I didn't read the instructions carefully enough - thought capitalisation meant the letter did not follow the rules! The solution was much simpler than I thought.
I failed this test... should ignore case: expected '(())())' to equal ')())())' I don't understand Each character occurs more than once, so it should equal ')))))))'... Anyone see what I am missing?
Probility your solution is wrong. read the description like carefully and try again. and if you share your solution we can help you. dont forget share your solution like spoiler.
Neither of those strings is the input. The first one is your wrong answer and the other one, the expected answer. To see the input, print it.
That was it! I was reading the test wrong. Found the issue. Thanks!
This comment has been hidden.
If it's not available in Codewars runner there is nothing that can be done in the kata. Please open a request here: https://github.com/codewars/runner/issues Btw, your code can be fixed and there is some other problem besides the one the error message is about.
This comment has been hidden.
Your solution fails this sample test:
Assert.AreEqual(")())())", Kata.DuplicateEncode("Success"), "should ignore case");
Description explains why your answer to this case is wrong.
I am pretty sure you needed it also in your MS VS.
Your solution has a bug. Bugs in your solution are not a kata issue.
why that stupid calloc ?
Unfortunately, returning user-allocated strings is the only thing which C translators knew back then. Fortunately, many new C translations are much better and use reasonable patterns for memory management. But still, user-allocated buffers is what you can see in most of old translations.
In this kata, this is at least specified with a comment in solution setup. There are some C kata where figuring out requirements and avoiding a crash is like poking in darkness.
for string: "))))))))))))))))))))))))" expected: "))()()(((()(())()))(()()" but got: "))))))))))))))))))))))))" can u help me with that test explanation? why should i return "))()()(((()(())()))(()()" ?
I cannot reproduce your problem with your current solution. Can you show your code which causes this problem?
Thans for answering, i've submitted another solution and it works now.
another good kata. time for the the next one.
This comment has been hidden.
You are missing a
{
at your function body, not a kata issueThis comment has been hidden.
This comment has been hidden.
what should i return in this function? just string?
i have made everything right, all outputs matchbut in the result i have red window, i thought may be i returned something different from what author wanted
help please! i am writing on c
Error on Python Having difficulty fixing the issue on basic test case "(( @" Sometimes it does give the right result sometimes it doesn't
Hi @Alterra Laniakea - the reason is that when you call
set(word)
the elements will not always appear in the same predictable order.To see this for yourself, after your line
... set(word):
addprint(i)
then run your code 10 times on the same input on your computer locally.For example, with the test case you are having problems with you will get different orders of symbols like:
, @, (
then maybe@, , (
then maybe, (, @
etc.Depending on which order gets generated by
set()
your logic will work differently afterwards. For example, work through the order, (, @
and see if you can understand why your code produces)))(
. Whereas for the order, @, (
it produces))))
This comment has been hidden.
Hello , I have a question on this command : string_.remove(k) this line doesn't work (from by class its supposed to work) maybe I've done something wrong
does someone know the command to remove a value from a string ? Thanks
This comment has been hidden.
No it isn't ok. Not a kata issue, print the input and check why it fails.
Is there a way to see what the random tests are supplying as arguments to the function you write? I can see what is supplied to the fixed tests, but all I get in the error read out is what was expected and what my function returned, but it would be more helpful if I could see what argument was being passed in during the random tests. I'm in Ruby. Thanks to whoever can make this clear! (I've been to the trouble shooting page but the part about printing out the error message didn't help me. If someone could tell me what to write into my code to see what is being supplied in the random tests that would be enough to help me do it for all the others. Thanks! (my language is Ruby)
Use
puts word
for ruby, then the same thing written in the docs applies.Anytime I hit ATTEMPT i get different fails and passes. The test cases with ( or ) keep switching from passed to failed; all except the "test.assert_equals(duplicate_encode("(( @"),"))((") ". What could be the problem? I'm using python
Hi @grayblack-code - when you press Attempt your code is being tested against randomly generated inputs, so if your code doesn't work it will fail some and pass some others randomly.
The best thing to do is to print the inputs you are encountering - learn how to do this in this guide here - and then debug based on what you notice.
I think it's to do with how you handle the ')' and '(' in your code - for example I tested your current solution: on input ')))' it produces ')((' while the correct answer is ')))'. That should be a simple enough example for you to trace through your code and see what is going wrong.
Thank you. I'll do that
It's telling me that I've failed "Testing for fixed tests expected '' to equal '(((' ". I'm not clear on what that means.
What does "Exit code: 132" mean? I asked before and didn't get any answer.
The program encountered an illegal instruction or undefined behaviour, e.g. trying to access elements of an empty array (or any of a plethora of things you might be doing wrong)
This comment has been hidden.
This comment has been hidden.
It won't let me test my code, it's throwing me an error from the test part itself.
File "tests.py", line 8 test.assert_equals(def duplicate_encode(word): ^ SyntaxError: invalid syntax
That is not my code. Also, my code works when I hit the "attempt" button, just not the test button. What my code did on the attempt button: Time: 524ms Passed: 48 Failed: 0
Click reset and try again.
заебись круто класс
Please write suggestion in English.
Doesn't work right with vector pairs. In VS 19 works fine
Hi - it seems you are working in C++ (please state this when raising issues, it helps the right mod/power user to identify your problem).
Also, please be more explicit when you raise an Issue - "it doesn't work" is not very helpful. Are you timing out? Are you failing specific tests but not others? Do you get a particular error message? etc.
In the mean time, until a C++ Codewars user sees your message: please read this page and see if any of these steps work:
https://docs.codewars.com/training/troubleshooting/#works-but-no
Your solution uses global variables, what causes bugs.
Bugs in your solution are not a kata issue.
Cant understand this one: Incorrect answer for 'CodeWarrior': expected '))(()())())' to equal '()(((())())', cause "C" and "W" are not double.
The expected value is
'()(((())())'
, your function returned'))(()())())'
. Debug your code.I see, my mistake, Thx for answer.
This comment has been hidden.
Hi and welcome to Codewars!
First, if you want people to read your code you should use Codewars/Github markdown formatting, as it is much easier to read and copy paste - you can learn how to do this here:
https://docs.codewars.com/references/markdown/
Also, very important for troubleshooting - you can print the inputs so you can see which ones are failing: do this by adding
print(word)
in your Python code:https://docs.codewars.com/training/troubleshooting/#error-messages-and-printing-your-inputoutput
Finally, for your solution - it is failing for tests involving
)
(
and other non-alphabetic chars in the inputs:"(( @"
" ( ( )"
so maybe you can slightly modify your code and things should work.
This comment has been hidden.
That's because
.replaceAll()
requires a higher Node version that the ones available.This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting/#post-discourse
yeah, sorry my bad, thanks
OP solved it, closing
This comment has been hidden.
This comment has been hidden.
That's because
.at()
requires a higher Node version that the ones available. You have certainly other ways to access a char in a string, use them instead or if you want toconvert input str to char arr
you have better built-in methods too.This comment has been hidden.
Read the error message:
Why is your function's name
getArrows
? Not a kata issue.Oh, i'm stupid...
thx, btw, it's working now
This kata seems to not work with .replace methods in JavaScript. I got solution right, and it works fine in node or devtools, but fails here with type error "replaceAll is not a function", because it gets confused with braces in quotes: replaceAll( word[i], ")" ). Or it simply do not accept solution with replace method. Tests are not parsing code in a right way.
replaceAll
is only available fromnode
v15. Codewars has onlynode
versions up to v14.I don't know why, when using replace with lower case it doesn't do it for me, but if with upper case, and I have to change the word and letter to upper case, it's weird
This comment has been hidden.
Hi, may you please kindly add a spoiler to your comment?
hey, if you take i from lowercase word, u should serch for it also in lowecase word ;)
This comment has been hidden.
hey guys. i am solving with js, and when i want to add ")" to string, it raises an error
SyntaxError: Invalid regular expression
. It works OK with letters, but not with "(" or ")". can anyone help?You cannot treat any arbitrary input as a regular expression, because this way you can create malformed regex.
For example, if the input is
"("
and you want to turn it into a regex in a naive way, you end up with regular expression of/(/g
, which is not a valid regex pattern.This task does not even need regex, regex based slution for this task is probably more complicated than even necessary.
ok, thank you mate, i'll do it another way.
Hi!
It works in my IDE but not here. The only test that fail is: "Supralapsarian"
That's because your solution has a bug. It does not work for a following test case either:
assert.strictEqual(duplicateEncode("aA"),"))");
Thanks for the reply!
Javascript: solutions which do not handle different case pass all random tests.
Random tests do not generate inputs with different case reliably.
fixed
Hello everyone, I don't understand the test: should ignore case: expected '(())())' to equal ')())())' but '(())())' should return ')))))))' - shouldn't it?
To see the input, print it: https://docs.codewars.com/training/troubleshooting/#print-input
Tests presented inputs but only for random tests.
I updated assertion meessages of fixed tests.
Chrono79, hobovsky, damn, I'm really stupid. Thanks for the answers!
Sample testCase error (Supralapsarian) in this string capital 'S' and 's' occur but expected output is for capital S is ')' and for small S is '(' Supralapsarian Expected output = )()))())())()( My output = )()))()))))()(
detail given in instructions tab "Success" => ")())())" here Small and Capital gives same ) bracket then why in Sample test cases small and capital letter gives different result.
The test in C++ is this:
Click reset if you see other thing.
i use C, and i passed all tests but the last one. i think it is a kata problem because it is the only one, function failed. also program worked very well in my pc locally.
Tests are fine (but they don't give the input when a test fails). What is happening actually is that the tests stop as soon as your code returns a bad answer. Your code fails on one fixed test, and in random tests. you should try to print the input using
printf
.I have a really weird problem with this. I am using javascript as language everything is going good. But whenever I try to return my result it's breaking my function. console.log() works how I want it but when I switch it to the return at the end it's breaking the loops and duplicate mess up with my result.
Example console.log(result.join('')) // prints: (((
return result.join('') //prints: ((((((
Also tried: console.log(result.join(''))> return (result.join('')) // which means I just deleted console.log() and write return. with parentheses included and without them. can anyone help me
You're confusing the output of two different tests, not a kata issue.
First I tried counting using a dictionary and using replace based on K,V pairs. and second I tried using replacing iterating over the word Both of these methods were unsuccessful.
I think for some reason it really really did not like using replace based on count values. I just couldnt get it to work in the end. I ended up giving up and saw most everyone using newstring += ')', which I was going to do but I was too stubborn because I wanted to use the K,V in dictionary. I think I overthought this one :(
really nice kata
good kata
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
The 'Success' test is not a good one to see if the user is ignoring uppercase. If they iterate through a lowercase array without changing the original word to lowercase, you still get the correct result because there are two lower case 's' at the end. A better test case would be something like 'Aba'
Thanks for this, now i get it why it's giving an error
This comment has been hidden.
Your code worked fine for me. Not a kata issue, click reset, maybe you messed up the sample tests?
nice kata
This comment has been hidden.
read this: https://docs.codewars.com/training/troubleshooting/
and this: https://docs.codewars.com/references/markdown/
This comment has been hidden.
Hi. It is not available in the NodeJS version used currently here. You must find something else.
I wrote it with c++. It has been a while since I wrote c++ or use this website.
If anyone want to check my solution: https://www.codewars.com/kata/reviews/5d5ed826ad2c6800010db5d3/groups/627fcd97d6bf32000121cd8e I would love if someone has any better practices to suggest to me.
Thanks!
This comment has been hidden.
If solution for this string: 'eyeedG)meOeeeben' , is that string : '(())(()()()))()(' , why firs element[0] and last but one[.length-2] is not equal?
This comment has been hidden.
No, it is fine, why do you say so?
From the kata's description
S
ands
are the same letter, ignoring capitalization.My bad. I kept re-reading the description and getting it completely opposite of the description, over and over again.
Helloo !
I'm stuck with this because in the problem say to ignore capitalization when determining if a character is a duplicate, but then in the tests i don't think it does what the description says.
Look at some examples:
"Success" => ")())())" <- here they are assuming that 'S' == 's', so the parenthesis are going to be ')' when a 'S' or 's' exist
Otherwise in the tests
"Prespecialized" => "(()(()()(()()(" <- it's assuming 'P' != 'p', so the parenthesis are going to be '(' when a 'P' ( but it should be ')' right ?? according to what is above )
Maybe i misunderstood If someone could help i appreciate ^^
Ps: C language
The expected value for
"Prespecialized"
is")()())()(()()("
. If you see another thing in sample tests, click reset.Ooo thank u so much ! I must have accidentally changed the tests, don't remember how xD It solved my problem, thx :)
The template should contain the name of the parameter, and it should be mentioned that this kata does not request for in-place replacement, in fact, it's not allowed to do that in C.
Yes, I had this issue when trying to come up with in inplace solution and realised a string literal is passed in.
The function signature should read char *DuplicateEncoder(const char *str); to signify that the argument is immutable.
added
const
qualifier + better failure messagesThe exercise talks of "characters" ("if that character appears only once") but treats the characters 'P' and 'p' as if they were the same. Badly written details.
but theres this:
This comment has been hidden.
This is not a kata suggestion, ie. a suggestion of improvement to the kata. Also, don't give free hints in Discourse, users are supposed to solve the katas by themselves, not by looking at Discourse page. Trying, failing and searching is always instructive, just like it has been for you.
good kata.
This comment has been hidden.
The tests are ok, the method works perfectly fine, you get an error because you're doing something bad.
This comment has been hidden.
The kata was really interesting and I've had fun solving this!
This comment has been hidden.
I don't know if that's the cause of your problem, but don't the input for output. Allocate yourself memory for the output and use it. In general that's the way to do the task in a kata asking for a string / array, unless the contrary is explicitly specified.
That was it, thank you sir.
finished my solution, but I getting this error, ReferenceError: Test is not defined. How would I do that? Can you please any suggestion?
Please say which language you are using.
using Javascript
Save your code locally and make sure you have the latest version of Node selected in the trainer
Node v14.x
at the top page. Pushreset
at the bottom and you'll get an updated version of tests. That should fix the issue.GOCHA THANKS
damnn
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Your code will fail for cases when the string contains characters like
(
and)
Hi Guys what could be going here ? The stuff matches... i am returning String as the assert expects
Taken from output: Basic Test Cases Log ((( None should equal '(((' Log ()()() None should equal '()()()' Log )())()) should ignore case: None should equal ')())())' Log ))(( None should equal '))(('
According to the output, you're either not returning anything, or you're returning None.
sorted, thanks
This comment has been hidden.
read this for help
please use question label next time as this is not a problem with the kata
also,
Thank you for taking the time to link the documentation. Very helpful. Gave it a read and will definitely have to try again.
hey folks, surely this is not correct? getting this when i attempt the case
i am also getting this in attempt
This means your code returns the first string, while the expected result is the second one (which would be a correct answer for input string ""aaaaaab", for example).
just to confirm does this :
mean that my code returned
()(()()angc))(()s(d))(
this string - tested this locally on my machine and my output is()(()(((((()((()((())(
granted my output is not correct either but it is far from what the tests are suggestingYou're doing something wrong. This kata has been solved more than 120,000 times (!), tests are ok. This can help you: https://docs.codewars.com/training/troubleshooting/
will have a look thanks for your help akar-0, it's probably some small logic i am not seeing
COBOL translation.
approved
Would be nice if the latest version of Node was being used so we could use modern code.
SyntaxError: Unexpected token '??='
This kata uses the latest Node version currently available on CW.
You can request update of JS runtime in Codewars runner repository: https://github.com/codewars/runner/issues
Why replaceAll() in JS not working on this site?
Because it requires Node v15: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll#browser_compatibility
Testing for word "VURU oRVpSLtvQWtivi": '))))(())())))))))))' should equal '))))(())((())(())))'
Thats WRONG TEST, fix it pls!
the test is not wrong
your code is presumably not checking for capitalization
No it's not. It's WRONG SOLUTION. Yes, your code!
"))))(())((())(())))" is the right answer for that input. If you compare the values, you'll see that your code encodes 'S' and 'L' as duplicates, but I don't see them anywhere else in the string.
This comment has been hidden.
Yes, there are random tests when you click 'ATTEMPT' (only a very few kata do not have random tests).
Hi, My test work but when I'm trying to submit I'm fetting the following error:
/* error start / Tests with '(' and ')' expected '))))))' to equal ')))))(' / error end */
According to my knoledge both options are wrong ( option '))))))' and option ')))))(' ). Did anyone know how to solve this issue? :)
Your function returned
))))))
for that test, but it should have returned)))))(
to pass the test.)))))(
is the correct answer.Tests with '(' and ')'
is not the input, that's the heading to that block of tests. Try logging the input for that test to see where you're going wrong.Thanks 👍 the console.log helps to see the input 🍻
I am a student in a university and I would need to have an answer to this exercise which could unlock me for one of my exams. Thank you I am studying for my January exams so this is really important!
Spoiling solutions is forbidden. To unlock solutions to a 6 kyu kata, you just need to reach the 7 kyu level. That's just solving a few elementary katas, it should be very easy. If you're not able to do it, you probably don't deserve to approve your exams!
thats deep
Bro wanna be carti so bad
This comment has been hidden.
No language specified and no code example provided. This kata has been solved a great amount of times, it's very likely your code doesn't work correctly. Please read carefully this before raising an issue: https://docs.codewars.com/training/troubleshooting/
This comment has been hidden.
This comment has been hidden.
JUnit uses square brackets to show which part of the actual/expected strings is different; not an issue.
This comment has been hidden.
There's no
issue
. The error message is correct.The
T
's are duplicates. All others are unique.This comment has been hidden.
This comment has been hidden.
code works fine on my compiler and i get the correct result but when i enter the same code to the test here i get a different result can someone help me?
Same exact thing is happening to me. But I don't think it matters in the long-run. This is an educational tool, so since I've verified my code works, I decided to move on to the next kata.
enjoyed this kata
This comment has been hidden.
Hello, you should not post code without the spoiler tag (I have added the tag).
Also, if you want to post an
issue
because you feel there is a problem with the kata code, you need to explain what the problem is and give some evidence, such as test case examples. This is just some code.Your code being wrong is not a kata issue.
This comment has been hidden.
Without seeing the input value it is hard to help you.
In output they dont show what the value they used for tests. :-(
Try printing it yourself:
thx, its help me )
This comment has been hidden.
That's a problem with your code, not a kata issue.
next
is raisingStopIteration
. When you fix your code, it'll work with both 3.6 and 3.8. Note your code will fail the last sample test tho.My bad. >.< It worked on python 3.9 in vscode without throwing any exceptions so I figured it was a kata issue. I shall be more vigilant next time.
Hi! I'm getting the "(" and ")" allocation I want, but all results fail. I've tried adding an additional str(response) validation, to no avail.
Please see if this paragraph, or article in general, is any helpful: https://docs.codewars.com/training/troubleshooting#expected-the-same
That did help - Thank you!
expected:<[)()))()))]))()(> but was:<[(()))())(]))()(> Other IDE's output: <()))))()))))))))> Looking for a solution...
Print the input, between the first line and the second that doesn't seem to be the same input.
What is here test string (3rd basic test)?
Kata.DuplicateEncode("Success"), "should ignore case");
This is uncallable in any IDE: DuplicateEncode("Success"), "should ignore case");
If you want to use the Codewars tests frameworks in you IDE you need to install stuff, depending on the language. You may wanna ask for help on CW's Discord channel, they will inform you.
This comment has been hidden.
Please don't post solution in discourse. The solution page is here for that. If you have any question, ask a question. And in all cases use a spoiler flag if you post code in a comment.
All right...
Nim attempt tests throw warnings:
I cannot replicate. It seems like someone cleared them at some point (the random tests use
rand
, notrandom
)This comment has been hidden.
NO, IT'S BECAUSE UPCASE LETTERS HURT THE EYES.
Good kata. Quite simple for 6kyu for my opinion.
This comment has been hidden.
I'm confused as to whether I should ignore case or not. It seems like some of them do and others don't
You should ignore capitalization, as the description says. Please provide some proof of those cases you say they don't.
Ok I figured it out. I was lowering the word but forgot to use that one as my variable. Thanks!
Why is this giving me a timeout when submitting even I have passed the test?
If it gives time out, you don't pass all the tests. It means your code is not fast enough, or maybe in some cases it gets lost in an infinite loop. Hopefully this may help: Troubleshooting Your Solution.
Please check Time complexity
How come I am seeing the solution prefilled ? And the tests seems to be broken.
This comment has been hidden.
Hi, something wrong with the submit. All my test ok but when I submit it says
'((((((' should equal ')))))('
but instructions says that any character more than 1 time should be displayed as ')' My output is ))))))' which is just according to instructions as all ( comes more than 1 time so they are all converted to )
'(((((('
is your output,')))))('
was the expected answer, print the input to know what it was.This comment has been hidden.
No, it doesn't, otherwise you wouldn't see that error.
That code is from your function. You can see what's the input value that makes your code fail there, it's
"CodeWarrior"
.This comment has been hidden.
Hey mine is working for letters only using .count. However not for symbols as they are counted as 0. Is there a version of .count which counts any character in a string? I can't seem to find one. Thanks!
If letter is duplicated in string, test says '(', but my program execute correct, and returned ')'. What the problem??
What language? You'll need to post your code to get any help. If it's python, I just solved it in python with no issues.
This comment has been hidden.
This comment has been hidden.
I get a fail for '))()' should equal '))((' this does not seem correct???
Read this: https://docs.codewars.com/training/troubleshooting
This comment has been hidden.
Your solution fails test case with input
"Success"
. Expected answer for it is')())())'
, but your oslution returns'(())())'
.this case is so dissimilar, can you give me a solution?
This comment has been hidden.
The error message of those tests tells you why your code failed.
This comment has been hidden.
I used Java, I am new to this language but yet I did come at end to a string that in System.out.println(thatString) show this for the test ")()())()(()()(" but for returning that string, like return thatString; , I have an eror "Unclosed group near index 1, ( " . I even hardcoded this string at return for test, and I have this eror anyway. I did an Array, a List and a String Builder and then all of them transformed to String, nothing seems to work...
This comment has been hidden.
closing as user error. The user likely created a regexp dynamically without escaping special characters.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Print input to console. For C# - that's Console.WriteLine() (don't forget to add
using System;
at the top)This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting#post-discourse
Thanks!
I tried with many solutions and nothing worked with javaScript. Codewars won't give me solutions. Hw can i solve this ?
It's solvable in javascript, you must be doing something wrong. Read this: https://docs.codewars.com/training/troubleshooting
Codewar is good but without solution it is not good. What if I couldn't solve a problem?? I want solution. But there is no solution given in codewars
If you want to see solutions, you can click the 'solutions' tab at the top, but you will have to forfeit the kata (ie. you will get no points for it).
In solutions tab It says "You have not earned access to this kata's solutions". This is so rubbish. It is okay to not able so solve a problem. Putting a barrier before solution is ridiculous. I am not lazy person who want's to see solution after trying 1/2 times. I tried too many times. But stil failed. Now I have given up. I want to see solution. But here is also barrier to watching solution. Thanks "Kacorott" For your support. I appreciate your suuport.
When you go to a kata you have not solved (or which you cannot solve), and click on its
Solutions
tab, you can see following text:You can click the button and unlock solutions, and then you can see solutions without solving the kata.
Note, his level is 8kyu, this kata is 6kyu, so he sees this:
Solve more katas (start with the easier 8 and 7kyu), reach 7kyu and then you could forfeit this one and see the solutions. AFAIK, you can unlock katas until one level above your current level.
If you read the link I posted, you could see how to post your code here and ask for some help about what's wrong with it. Maybe you're using
console.log
instead of returning?Hello everybody, I really like the Idea of this kata. However, there is one big problem that I faced: When looking at the tests, the creator of this kata implies, that 'S' is equal to 's'. So all uppercase characters are to be treated the same as lowercase characters. From my point of view, that is a wrong implication, since 'S' and 's' have different ascii codes! Change this please or make it clear in the description of the kata. Aside from that, great kata:)
It's already there in the description.
This comment has been hidden.
reread the description for conditions that the question requires
maybe capitalization is the reason?
Why is the case "(()))())())()(" not "))))))))))))))"? All the characters appear more than once.
are you sure you're not comparing your output with the expected output?
Yea I just realized, was just gonna delete it.
Could someone explain this please?
So I've solved this Kata all except for the last character in the string. My solution compares each character in the string to each one after it (to avoid comparing it to itself). However with the last one, there is nothing after it to compare to so it thinks that it's always a unique character. What are some ideas that could solve this problem?
This comment has been hidden.
The problem may be that when you allocate your char array with
c = (char *)malloc(sizeof(char) * (i + 1));
, you are not setting the last elementc[i]
to 0 (or'\0'
). Remember thatmalloc
does not initialize any memory, it only allocates it (butcalloc
will initialize to 0). This can cause a problem withstrcmp
since it compares the strings up until it reaches 0 on one or both of them.This comment has been hidden.
Yes. well, that's because you use
replaceAll
and that method doesn't work with available TS versions.This comment has been hidden.
Yes, it is you, print the input, see for yourself why your code fails. Read this too: https://docs.codewars.com/training/troubleshooting
Thanks for the reply. After trying another kata I managed to determine a slicker solution which passed all the tests. However, I think the issue may be that I hadn't understood which inputs were causing the failures and so hadn't been able to replicate them. Just inexperience I guess. Thanks again.
This comment has been hidden.
This comment has been hidden.
check out the fixed test it fails:
My code works perfectly on python and I get the right answer but apparently when pasting it here it says I get something else. Example: CodeWars: duplicate_encode("ya(ew(lzQ)") - wrong "))))))))))" should be "(()(()((((" The same code not on CodeWars: "(()(()((((" I have checked a bunch of errors and I always get the right answer yet on COdeWars it says I got it wrong, plz fix.
Please see if anything here helps: https://docs.codewars.com/training/troubleshooting/#works-but-no
I just checked my solution and it still works, tests also seem to be OK.
I am going to close the issue as invalid, and you could just go through the FAQ I linked above and try to find the problem with your solution. if you are sure you are 100% correct, post your code here.
.
This comment has been hidden.
Please read how to post code here: markdown formatting (otherwise your code loses all its indentation) and mark your post as having spoiler content next time. You're using a global var there, so it'll fail when your function is called several times in a row.
From the link hobovsky told you:
hey guys i tried tested my code and it passed 3 out pf the 4 tests mentioned. the one which went wrong gives a message like this:
i tried adding main to the code with "success" as an argument to the function and it gave me the correct result as mentioned in the instructions:
Are you ignoring casing of the later as the message told you? Cause there is a difference between "success" and "Success", if you dont specify to JS that you dont care if its capital S or not, then it wont recognise it as equal value.
Loved this one
This comment has been hidden.
Hi, you should know it is forbidden to post your code like this in the discourse. (I have added the spoiler tag).
This comment has been hidden.
Hi, you're passing all of the random tests but failing on one of the fixed tests. I suggest you
printf
your inputs to see what chars your're getting.Please, help me to understand. My C# code has passed all basic tests but has failed Parentheses Tests and Random Tests. ParenthesesTests Test Failed Expected string length 6 but was 5. Strings differ at index 0. Expected: ")))))(" But was: "(((((" -----------^
RandomTests Test Failed String lengths are both 18. Strings differ at index 3. Expected: "((()())(()()()((((" But was: "((((((((((((((((((" --------------^
Your code failed for cases when your string consists of characters like
(
and)
can anyone help me I'm facing some problems with @
I am trying to solve this using dictionary in python. I am saving the number of occurrences of each character in the dict. And I check if that character comes up more than 1 time then I replace the character with ')' else with '('. The problem is for example if the word is "abca)" then when the interpreter gets to ')' it replaces all the previous occurrences of ')' with '(' as ')' occurrs only once. I don't understand why it changes all the previous occurrences and not just the current one. So my answer comes out to be "(((((". This problem does not happen in for example "abca(". For this I get ")(()(" which is the correct result.
Hey I am Searching for someone to practice programming with... Are you interested.?
This comment has been hidden.
This comment has been hidden.
If you use this hack again, you will get banned. Not an issue.
This comment has been hidden.
That's JUnit telling you in which part of the string is the difference, the square brackets aren't part of neither of them.
thank you :)
This comment has been hidden.
This comment has been hidden.
Please remember to use the spoiler tag when posting code, otherwise everyone can see it. (I have added the tag). For your function, return the value instead of print.
Read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
Also, if you post your code, use proper markdown, otherwise the indentation obfuscates the code.
This comment has been hidden.
Don't return print(whatever...
Just return.
Well, good day everyone! I have the solution and it is working perfectly in VS Code. But here, it is giving me the following error! ! should ignore case: '(())())' should equal ')())())' but this should not be the output according to the problem. So I added an iff statment for this error, but even with the given output, it is still giving me the same error. Am I not understanding it correctly? Is there something missing that I am not able to see? I would really appreciate if someone can help me in this.
You haven't mentioned what the input was, so I wonder if you used the same input when you tested that case.
I added this condition; if word == '(())())': list.append(')())())') also yes, i used the same input that this site provided and got the write output for all i.e., 'Success' and 'recede'.
But the
word
is"Success"
isn't it? Not"(())())"
What i was saying was that my code worked perfectly with Success and recede, but when i tested it here, it will give me following error
should ignore case: '(())())' should equal ')())())'
meaning, it is saying that above input should be equal to the above given output. but that should be not possilbe since every paranthasis is being repeated. so the output of '(())())' should be ')))))))' and not ')())())'.
I was asking if there is some problem here or not. Check the following code and see if there is any problem here;
def duplicate_encode(word): ....#your code here (Here periods are substitue for indentation as it is not working with normal spacing) ....list1=[] ....for i in word: ........count=0 ........if word == '(())())': ............list1.append(')())())') ............break ........for j in word: ............if i == j: ................count+=1 ............if count>=2: ................list1.append(')') ................break ........else: ............list1.append('(') ....str1=''.join(list1) ....return(str1)
Means
S
ands
are the same letter. How is your code doing that?Ah! Thanks! I had it in my VS but forgot to do that here.
This comment has been hidden.
Richeskelechi: don't post code like that.
PHP:7.0: I created the function but when it is running the test it failed. I tested each test individually in local environment and it is giving the right results.
More than 3000 persons (and I) have solved this kata in PHP and had no problem. Do not raise an issue without substantial arguments: logs, example of failed cases, code (with a spoiler flag)... Your code not working and you don't know why is not a kata issue. See here if it may help: https://docs.codewars.com/training/troubleshooting
This comment has been hidden.
You're not returning anything.
This comment has been hidden.
Good eveving every one,
I believe i got the solution, it pass the test, but i got an error anyway.
Could anyone help me ? thanks
do you get timed out? in that case your algorithm isn't efficient enough, if you fail tests your algorithm is wrong somewhere, try to find out what exactly you did wrong in that case and fix that!
there is a way to see all the tests that have been aplied ? I m passing just the example. and I pass if hit test button, I don't get why I am passing the test and not the attempt:
Read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
This comment has been hidden.
On the 4th row you should have:
for i in set(wlo):
Because you are trying to loop through the original input string with the cases intact.
This still doesn't fix the code but at least it's one step in the right direction
This comment has been hidden.
Your code being wrong is not a kata issue, please read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
You can see it fails a sample test, start from there and debug your code.
This comment has been hidden.
Please read this.
This comment has been hidden.
Not a kata suggestion:
From here: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
Oh! Sorry.
This comment has been hidden.
Copy and paste this sample test:
See the error message:
$$
$$
))( <- here there is a weird char (it doesn't show here)
It's a problem with your code. Please, read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
This comment has been hidden.
It may have to do with the sequencing of the program. In the first one, you're directly placing the lower() method into the for loop, while the second one is assigning it to the variable, then placing the variable into the for loop.
I tested the second method, and it seems to be case sensitive as well. Perhaps the case sensitivity issue lies in the content of the for loop, and how it works when used with option 1 or option 2.
What did you put into your for loop? I assume you had the same loop for both option 1 & 2, but perhaps there might be a 'clue' in the loop itself?
This comment has been hidden.