6 kyu
Backspaces in string
5,221 of 19,233vetalpaprotsky
Loading description...
Fundamentals
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.
Too easy for 6 kyu
Nice!
This comment has been hidden.
In JavaScript I get: expected ' ' to equal '6+yqw8hfklsd-=-f'. When I run the function in VS Code it retuns '6+yqw8hfklsd-=-f' not emply string(''). Am I doing something wrong?
Yes, your code fails to handle certain inputs. Not a kata issue.
Also, please use the
Question
label if you're unsure where the issue lies. See https://docs.codewars.com/training/troubleshooting#post-discourseDone in C++.
Для меня описание принципа работы '#' было не достаточно и 6 примеров для тестов было мало, чтоб понять. Пришлось подглядеть готовые решения, из решений составить список для тестов и по их результатам только стала понятна задумка '#'. Тогда сразу получилось своё решение сделать.
Language: C++
Test suit missing the required header
std::string
The description should state clearly that the input string is composed by ANY character
There's a CPS-based solution to this, isn't there?
what i don't understand if i use s.replace('#', '\b') it works perfectly on pycharm. but not here ?! any one knows why ?! thanks in advance
I do honestly doubt it works in PyCharm.
What does this code print in PyCharm?
print('ab#'.replace('#', '\b') == 'a')
if use
print('ab#'.replace('#', '\b')
it prints 'a' it useprint('ab#'.replace('#', '\b') == 'a')
it prints False but Why ? i thought it works perfectly on pycharm now i am just confused :D ifabbc####f#l#V'.replace('#', '\b')
it prints 'V'it prints false but why ?!
That's because when you do
"ab#".replace("#", "\b")
, you get"ab\b"
as a result, and not"a"
. And when you print the"ab\b"
to the screen, it may (but does not have to) look like justa
.So basically what you print looks like
a
, but in reality it is"ab\b"
(three characters), which is not equal to"a"
.OP solved it, closing
Great outside-the-box kata
Update to Scala 3
.
Do not really understand a task. Can someone help me pls???
A "#" means that u have to delete(or backspace) the letter before it. Example : a#b = b since ur deleting "a"
Now I got it, thank you very much!
expected 'rcvciotvshjtpttzrjrphncluxcqlkueycfiaiqqwajkmamocxtqjywkdbpjpyfxufrkgkctbnmtwrxlxtntmj' to equal 'frcvciotvshjtpttzrjrphncluxcqlkueycfiaiqqwajkmamocxtqjywkdbpjpyfxufrkgkctbnmtwrxlxtntmj'
I can`t understand that . Why there is 'f' at the start?
This - I'm guessing - is a random test rather than a fixed test, so we will never be able to reproduce the exact same input. However, if you are confused about what's going on + want to troubleshoot you should print the input:
how to print the input
In this case, remember that Expected "rcvc..." to equal "frcvc...." means your code is returning the first string and the correct answer is the second string. So there is an "f" at the start because in the correct answer, the "f" should not get deleted, while in your code you are presumably incorrectly deleting it.
Hi@everyone i'm having problems with my kata when i hit test or attempt it says " timed out conection blah blah " anyone to help me ?
Hi @derekMgwena - all kata on codewars have a timeout limit; depending on the language you are working in that can be something like 10 - 15 seconds, which is the maximum allowed time for your code to execute.
If you are timing out, it is because your code is taking too long to solve the kata - even though it might eventually obtain the correct answer if you let it run for a long time.
In other words it is not efficient enough; you need to find a better (faster!) algorithm
If you think that this is not the case, then you can check for alternative explanations here:
Timeout troubleshooting
Factor translation
Approved
5 lines of code but it times out... I guess this should be solved without any loops or recursion? Nvm... xD Tricky.
The speed of a code is independent from its number of lines. Most solutions (if not all) use loops.
This comment has been hidden.
Go translation
Approved
Damn. I started to smoke again. And it's so embarrassing to see the solutions of other
To be fair, is it really kyu 6? It could absolutely be a kyu 7 kata. But anyway std::cout<<"Nice kata";
yes bro, it should be 7 kyu
read this bro ;)
Bad output! char* ptr = "Nice Kata"; std::cout << *ptr; Tha'ts Better : [AKA C pointers version]
console.log("I really enjoyed this kata!");
Nice kata! ^^
TS: missing return type in initial solution setup
I got it, what should i do? (C++)
UndefinedBehaviorSanitizer:DEADLYSIGNAL ==1==ERROR: UndefinedBehaviorSanitizer: stack-overflow on address 0x7fffbca4a000 (pc 0x000000425520 bp 0x7fffbca490e8 sp 0x7fffbca48bf0 T1) ==1==WARNING: invalid path to external symbolizer! ==1==WARNING: Failed to use and restart external symbolizer! #0 0x42551f (/workspace/test+0x42551f) #1 0x428149 (/workspace/test+0x428149) #2 0x4269ce (/workspace/test+0x4269ce) #3 0x426523 (/workspace/test+0x426523) #4 0x4260fb (/workspace/test+0x4260fb) #5 0x42ab15 (/workspace/test+0x42ab15) #6 0x42577d (/workspace/test+0x42577d) #7 0x7fe13021abf6 (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6) #8 0x404569 (/workspace/test+0x404569)
==1==ABORTING
When you read the error message you see that it's a stack overflow error so probably your solution causes too deep (infinite?) recursion, or creates a very large stack variable.
Maybe. But, it is occurring when I make an attempt to return the string. A string is modified after erase all '#' wtih std::string::erase. Also, I can output the modified string to the console.
Maybe. But my C++ solution still works, so I still think there's mistake in your code.
This comment has been hidden.
Since upon every iteration which satisifes a specific condition, the string
s
is updated, resulting in length change. This happens cocurrently with the increment ofi
in which the position assessed by it in the string is not correct anymore. (i.e, not following the original positioning of each characters in the string)Example:
For case #3 above, the original behaviour should be
s[i] = 'c'
guys actually it seems that my solutions works beacuse when i try some tests on my ide it works but on the tests it crashes and tell me: Test Crashed Caught unexpected signal: 6 i m using c thanks for helping :)))
Please see if this paragraph of FAQ helps: https://docs.codewars.com/training/troubleshooting#appendix-errorcodes
Node 18 should be enabled (Refer this and this for more info)
Python new test framework should be used (Refer this & this for more detail)
Ruby 3.0 should be enabled (Refer this & this for more detail)
This comment has been hidden.
The tests are ok, your code is wrong.
Why are you using other symbols like backspaces too?
Test Results: all passed cleanString_test STDERR UndefinedBehaviorSanitizer:DEADLYSIGNAL ==1==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x0000000001ff (pc 0x00000042b16e bp 0x7ffc44d90f18 sp 0x7ffc44d909a0 T1) ==1==The signal is caused by a WRITE memory access. ==1==Hint: address points to the zero page. ==1==WARNING: invalid path to external symbolizer! ==1==WARNING: Failed to use and restart external symbolizer! #0 0x42b16d (/workspace/test+0x42b16d) #1 0x425648 (/workspace/test+0x425648) #2 0x428289 (/workspace/test+0x428289) #3 0x426b0e (/workspace/test+0x426b0e) #4 0x426663 (/workspace/test+0x426663) #5 0x42623b (/workspace/test+0x42623b) #6 0x42ac55 (/workspace/test+0x42ac55) #7 0x4258bd (/workspace/test+0x4258bd) #8 0x7fa2a874ebf6 (/lib/x86_64-linux-gnu/libc.so.6+0x21bf6) #9 0x404639 (/workspace/test+0x404639)
UndefinedBehaviorSanitizer can not provide additional info. ==1==ABORTING
you perform out-of-bounds write
Solve it on TypeScript, but test failed on: 'O#Q#p#EL#3nj3##': expected 'Enj' to equal 'E3n' If we have ## at the end of line, we should remove 3 than j. But we expected j in answer. How does it works ?
'O#Q#p#EL#3nj3##'
C++ version generates warnings.
Fixed
I cant pass last random test in C. Test Crashed Caught unexpected signal: 6 What does that mean ? Can i look at the randomtests?
Clojure Translation ready for review
'alr approved some time ago'
This comment has been hidden.
Done :)
ReferenceError: cleanString is not defined
Why this error? What is the actual function name?
In js,
cleanString
is the function name provided which you must use to solve the kata. So, you must have destroyed it. (?) Anyway, this is not a kataissue
. Anissue
would be if there is a problem with the kata, not your code. Instead you could post as aquestion
.I am using "cleanString" as my function name, but somehow it says it is undefined. Why?
hard to say, I would have to see your code. you can post it with a spoiler tag, we will find out then.
This comment has been hidden.
Any idea why doesn't it work?
This is an issue with this kata.
It doesn't support anonymous functions. Try and use the
function cleanString () {}
notation instead.Fun recursion and regex paradigm kata. Reminds me I need to dig into regex deeper and better!
Nice kata!
Solved it on Ruby, but one of the tests fails: Expected: "6+yqw8hfklsd-=-f", instead got: "6+yqw8hfklsd-=-fd"
But both strings are different? And without the input there's no telling what is the correct answer.
You didn't solve the kata though and this is one of the fixed tests, all I can tell there's no problem with kata but with your code ;)
Me too. Did you find any resolution?
Most solutions I find to this in C seemingly are inefficient with memory. They allocate memory according to the length of the source string, and make no effort to clean up the memory later. I'm primarily an embedded dev, so I'm very concerned with memory use if I can.
My solution cleans up the memory afterwards by duplicating the string (that's terminated, but has too much memory allocated to it) to another pointer, freeing the original (longer than necessary) string and returning the size-optimized string.
What's your opinion on this? Of course, if this is all used in a local environment that temporarily exists, which properly frees memory by some mechanism after it's done it's job. Then it's no problem. But if this function is run many times without freeing memory, my cleanup will use up less memory in exchange for a bit of processing time.
What's best practice? Assume that output strings are only used temporarily and freed later, or make the strings effectively use space at the expense of processing time?
I am not a professional C developer, nor embedded developer, but I do not like your approach either. First of all, length of resulting string can be calculated exactly, going once over the string. Just use
newLen = strlen(input) - count('#')
(handling#
s close to the beginnig of the string appropriately). If, for some reason, you want to really avoid over-allocations, then calculate length of the result first, and fill in the buffer later. Nothing gets wasted this way, on no stage of the operation. Your solution needs twice as much memory at some point, because for short time it keeps initially allocated "too long" string, and later allocates a buffer of "appropriate" length, having two buffers. You can avoid it by expense of precalculating the required length.Other thing is that allocating the buffer inside of solution is not that good in itself. I think it would be better to make allocation responsibility of the caller (after all, caller becomes the owner of the buffer anyway), and caller could even use some kind of preallocated memory pool to keep the result and avoid necessity of freeing it, or avoid problems with memory fragmentation, etc.
Nice insight, didn't think of that.
My solution was a clear case of "Wait, it works, but what about the memory" - and I chose the path of least resistance and brain usage.
I also agree about leaving the allocating to the caller - but this is not (?) realizable within this Kata.
If you are interested, you can see PoC of my idea here: https://www.codewars.com/kata/reviews/5e072bf6bb26620001ec1da9/groups/5f458d53e0be5a0001d0e55d
Unfortunately, not.
Hello everyone, I solved this task, or I just thought that it is solved.
My solution is broken after click ATTEMPT. If I test my code in Visual studio or GDB online, the program returns a good value. But in kata's tests wrote for example:
Actual: "gd"
Expected: "gdasda"
String: "gfh#jds###d#dsd####dasdaskhj###dhkjs####df##s##d##"
But when I test my solution in VS I got "gdasda", this is what you expect.
This comment has been hidden.
Hi, I looked at your code; it's not correct, but you can fix it out by printing out
tmp_Buff
,i
,tmp_Buff[i]
, andlen
each time they change and see if they're what you'd expect them to be.I'm super confused about this Kata, it's too algorithmic, I need help guys, any tips pleaseee)))
Try doing it by hand first. Then let the computer do what you did.
Great! Thanks for the best advice ever!=)))
Oh damn, I'm really out of shape. I solved it, but not in the nicest way... :P
My first thought was to create a regex pattern that would handle it all for me, but I couldn't figure it out since I'm shit at regex... had to look for a different way, but even then... a lot of unnecessary stuff in my solution.
Nice kata.
i got a "Double free or Corruption Error" on c++. What could be causing this?
pls help i couldn't solve this kata
/For the start try to remove all #s. Then think about removing the letter before # (...if there is any)/
Of course it's easy kata. But I'm trying to solve all katas using LINQ and I spend some time to found the solution for this one. Thank you for this kata. :)
Easy Kata :)
This comment has been hidden.
If the first character is '#', array.splice(-1, 2) is called, but splice rounds up to 0 for negative indices, so it calls splice(0, 2) when you wanted it to splice(0, 1)
@stellartux nice eye :D. Thanks for reply it helped me to solve this cata :) Cheers!
couldn't resolve this kata
Raising again both issues, if you can't solve it left it open one week so a power-user can really solve it.
AFAIK both things can be changed without disabling old solutions. See kazk's post below.
I've fixed the camelCase issue, but I don't think there's a way to swap the order of the actual and expected values.
I'll try in a week.
Thanks for your help guys!
Java
actual / expected also back-to-frontFixed both javascript and Java issues.
Typescript translation
The actual and expected values are swapped in the random tests in JavaScript (at least).
Tests can no longer be editet for JS. I know, it's a problem, but tests still work properly.
They can for 10k+ users, so leave an issue open for a week and someone can fix it.
The function name should be in camelCase in JavaScript.
Unfortunately I cannot edit javascript tests. Due to that reason I can not change the name of the function.
This problem was mentioned long time ago. Can't do anything about it.
Elixir translation awaiting approval.
Julia translation
Scala translation available for review.
C++: https://www.codewars.com/kumite/5bead9093952ceac00000250?sel=5bead9093952ceac00000250
Python translation kumited -- please check and approve
Thanks
Elm translation published
Thanks for translating to Elm! I liked the way you wrote fixed tests.
I also found a bug that I'm not sure how to fix :( Looks like the output of
Debug.log
is messed up. I had assumed tests were executed sequentially after each and attached the output ofDebug.log
to the events from the test runner, but it seems like multiple tests are executed at once.TYVM for doing this!! Loving learning elm through these kata
If only you can show what you have entered in the error prompt
Codewars Forums - Kata Best Practices - Follow Conventions
JavaScript Version: Identifier names (i.e. variable/function names) should always be in
camelCase
(except for constructors, but that is something else entirely) and notsnake_case
(source: W3Schools) - please change the name of the user function fromclean_string
tocleanString
.Resolving this 2 year old issue because, while camelCase is the norm for JS function naming, the casing doesn't break the kata. At this point, making such a cosmetic change would invalidate the nearly 500 submitted JS solutions, so it seems more sensible to leave it as is.
For JS, there should be some ways to change without invalidating:
If it's not possible for some reason, maybe add some comment in initial code explaining that and change it to something like:
my code passes all sample tests, and passes all fixed tests on hitting "attempt", but my attempts still fail because it times out after that. I'm guessing something in one of the random tests is causing it to loop infinitely, I guess? I don't want to get into spoilers, but the only thing I could think of that might cause a loop was a random string starting with too many # symbols before it got to letters. I wrote several different possible lines to account for that, though, and none of them prevent the timeout. not sure where to go from there, since I can't see what test is causing the problem?
It would help if you mentioned which language has this problem.
It would also help if you could determine what the actual argument was that's giving you trouble - but the problem might be in the generating of the random argument or the processing of it; in the first case you'll never getit of course.
ah, sorry, didn't realize these discussion pages weren't language-specific. I'm doing it in javascript.
and yeah, I'd love to see what argument was actually glitching it. I take it there's no way on here to see what random ones it selects?
i have similar problem on python
Hi, I made a C# Translation for this Kata.
random tests needed
Yes there are random tests. Closed.
Oh fuck, the stupid js author doesn't write random tests. I completed using Haskell. I'm sorry. Random tests are added.
(JS)
Test.assertEquals(actual,expected)
, not the other way around. I'd edit it for you, but I can't.