6 kyu
Decode the Morse code
4,286 of 120,878jolaf
Loading description...
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.
It took longer than I thought to solve this problem. Im glad I did it tho ^^
You have to be kidding me. Seriously? I didn't need to make the programming for which combinations of .s and -es mean which character?!
You can if you want to, but you do not have to. There is a preloaded table which you can use to map Mose code to a character.
sorry, i commented on this thread by error.
Could you specify what's the relation between patterns and special characters?, because your tests don't seem to use the characters shown in the International Morse code binary search tree as shown on the link you provided.
I just checked the special characters and they seem to be the same as on the linked Wikipedia page. What characters exactly do you think are tested incorrectly?
your & is composed of 7 signals, while in theory, following the binary search tree in the wiki article, there can only be 6 signals at a maximum.
No random tests in Java
This comment has been hidden.
For those doing this, especially in C, make sure to read the first 'NOTE:' carefully. Lots and lots of debugging happened because of overlooking that part.
Typescript tests show
<pre style='display:inline'>Got ' E E', expected 'E E'</pre>
(that is, they show the raw HTML and not an inline pre element)fixed
How downlooad MorseCode? Where is link?
who added the std::string decoded in c++ ? It does nothing
replaced the weird initial code by a simple
return "";
Despite passing the tests I get a 'Cannot invoke "String.isEmpty()" because "str" is null' error when I attempt. I didn't have a String named str but I made an empty one, same thing. Can't see the tests throwing the error so I'm not sure what I can do to find what isn't working. Training in java 17 if that makes a difference.
This comment has been hidden.
on Codewars:
return
a value, and do not care about what you log to the consoleMy bad, its only my third day out here. thank you though!
MorseMap for local tests
kotlin val MorseCode = mapOf<String, String>( ".-" to "A", "-..." to "B", "-.-." to "C", "-.." to "D", "." to "E", "..-." to "F", "--." to "G", "...." to "H", ".." to "I", ".---" to "J", "-.-" to "K", ".-.." to "L", "--" to "M", "-." to "N", "---" to "O", ".--." to "P", "--.-" to "Q", ".-." to "R", "..." to "S", "-" to "T", "..-" to "U", "...-" to "V", ".--" to "W", "-..-" to "X", "-.--" to "Y", "--.." to "Z" )
Thanks!
This comment has been hidden.
you are wrong, the Morse encoding of the comma is
--..--
, the dot is.-.-.-
, check here. The preloaded Map in Java encodes those correctlyWhen I press "attempt" in output shows a another values(broken or random), but when I testing this code in my computer all works good. Please fix random test. C language.
The same issue. I wish anybody fix random test of this "smart guys" who create this broken tests.
"Works good on my machine" is not a reason to create an issue. Wrong C code has this annoying habbit of working on one machine, but not on another.
If you want us to fix the issue, you need to show your solution which you think is correct, so I can test it and see why it fails.
This comment has been hidden.
The solution you shared has more than one problem: it allocates too short buffers which cannot fit the null terminator, seem to not handle leading and trailing spaces well, etc. There is a bunch of things which need to be fixed there.
Then why is everything working fine on my computer?
this is not how it works - you have to prove that the issue comes from the kata and not from your code.
because you are not testing your code toroughly on your computer. Try to re-create the fixed tests that you are failing.
Please do not raise issues so lightly. Use questions to ask for help.
For any tests your code does not pass you can simply copy the error feedback and then recreate those tests in your outside testing envoronment:
Also, this is not a new translation. Over
six hundred
coders have successfully solved this kata in C. By now any legit problems would have already been discovered.This comment has been hidden.
I am not sure what exactly you mean by "partial messages", but there is this note in the description:
I do apologize, I didn't see that note. What I meant by partial message is, if I receive a space before the first morse token, I have to decide why why that space is in the stream, because sppaces normally come after tokens. I can just assume the first token was delayed, causing the space, or I can more safely think there should have been a token before the space and my message will not be complete. Then I can signal the sender to retry or something like that.
Great kata though, I'm not at all complaining.
Was it just me, or were the unique situations not recognized by the imported library? Was using Java. If I'm not the only one, sorry but this Kata needs work then...
It was just you. The "the imported library" is fine.
if morse doesn't have spaces, that's not morse man
BRO JUST PUT THE ALPHATBET IN THE DESCRIPTION IS JUST PAINFULL BEING STUCKED IN A CHALENGE BECOUSE LACK OF INFORMATION ABOUT THE CONSTRAINS
There should no need to put the alphabet in the description, because the alphabet is made available to you as a preloaded variable. Just use the variable, instead of typing in all the alphabet, or copy/pasting it from description.
I understand that they want to use preloaded variables, but I believe that as programmers, and as individuals inspecting new code, it's important to provide a clear understanding of the code's capabilities. It's crucial to avoid creating a "black box" effect regarding the constraints of the problem. Clearly stating these constraints helps in understanding the full context and ensures that the code is transparent and easier to work with.
Hello, I was trying to solve this kata in C and had problems with random tests at freeing pointer I believe (I don't remember exact error message). I was trying reproduce this error to attempt to solve it, but I didn't managed to reproduce it. I tried to output the random tests to try them out, but I still didn't get any error message. Now when I again run the tests (to write down error message and at the same time get another set of random tests) I passed the tests, while there was just 2 random tests there. (I beleive before there were 100 random tests needed, and I was able to output about 20 of them before the error appeared.) What can I do to reproduce the issue, or was there something wrong with kata and that is being fixed right now?
Your code contains undefined behavior. As a result, its behavior is unpredictable, this is why it sometimes passes and sometimes fails. I ran your code in a static analyzer and it seems like you do not always allocate enough memory for the
ascii_string
. In particular, it seems to happen when the input contains SOS signals - since they need 3 characters to be represented, as opposed to the other symbols.This comment has been hidden.
eeeee... what&!!:)) 'expected 'SOS! THE QUICK BROWN FOX JUMPS OVER T…' to equal 'SOS! THE QUICK BROWN FOX JUMPS OVER T…''
You've already passed the kata, but I've edited the javascript tests so they don't truncate the output in the error message.
This says MorseCode dictionary is preloaded, but java code is not able to find the class. How to load the dictionary. Please help
You shouldn't import MorseCode, just call it as shown in the kata's description:
i did that and it is complaining class not found.
src/main/java/MorseCodeDecoder.java:10: error: cannot find symbol sb.append(MoreseCode.get(tkn)); ^ symbol: variable MoreseCode location: class MorseCodeDecoder 1 error
its loaded in the class of codewars not in your class so you you can only use it when you run the code here
This comment has been hidden.
Your solution seems to work fine for me, and the network error sounds unusual. Can you submit solutions to any other kata? Can you submit your solution to this kata again in a couple of minutes?
OP passed the kata, closing.
In Haskell I get the following error when attempting:
expected: "SOS! THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG." but got: "?! THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG. "
Weirdly this test goes through! decodeMorse "... --- ... -.-.-- - .... . --.- ..- .. -.-. -.- -... .-. --- .-- -. ..-. --- -..- .--- ..- -- .--. ... --- ...- . .-. - .... . .-.. .- --.. -.-- -.. --- --. .-.-.-"
shouldBe
"SOS! THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG."Good, BUT i don't find inner Java morse code. You will need to write detailed how find this
the description tells you:
C fork
I merged this one as an improvement, but TBH I am stil a bit concerned with the fact that user-returned buffers are used as a part of failure message without sanitization. But I have no good idea how to address this in a convenient way.
in the C version, I am getting a memory leak. when printing the contents of the morse_code for the random tests;
at least it looks like one, I get extra text and content that shouldn't be normally available in text.
Your result is most probably not null-terminated correctly, but it is difficult to say without seeing your code. You'd have to post your code here (remember about code formatting!) so we could see what is wrong with it.
I ran your code in a static analyzer and it contains undefined behavior in several places:
current_letter->length++;
even thoughcurrent_letter->length
has not been initialized (look at the initialization ofcurrent_letters
, you callmalloc()
and initialize thestart
field, but notlength
)letter* letter = word->start;
, you can end up withword->start
being uninitialized at that point (I did not check the code path that leads to that, because your code looks really complicated. You are implementing a linked list of structures in a single function, with a lot of pointer aliasing going on)Closing, as undefined behavior in your code is not a kata issue
This comment has been hidden.
Yes, this is the way
strtok()
works. Delimiters can only be single bytes, or in other words,strtok()
treats one delimiter byte or several adjacent ones the same way. The second argument is treated as a set, not as a sequence.delim = " "
anddelim = " "
are functionally equivalent and will produce the same tokens. Same for e.g."+-"
and"-+"
.You will need something else if you want to differentiate between
" "
and" "
.This comment has been hidden.
The
Issue
label is for provable kata issues. Please use theQuestion
label when asking for help and appropriate markdown formatting when posting code. See https://docs.codewars.com/training/troubleshooting#post-discourse.Yes, that's a valid way of accessing the values in
MORSE_CODE
. The problem with your solution is the incorrect logic.Not a kata issue.
Thank you
This comment has been hidden.
It's already there.
I'm failing on this test, and i dont really understand what its meant to return, the input contains no .... or __ but it still expects E E?
Great thankyou, just solved it!
This is pretty rough in NASM.
This comment has been hidden.
hi, i put the spoiler flag on your comment because of the code in it
consider this from the description:
Yes, this is the way
strtok()
works. Delimiters can only be single bytes, or in other words,strtok()
treats one delimiter byte or several adjacent ones the same way. The second argument is treated as a set, not as a sequence.delim = " "
anddelim = " "
are functionally equivalent and will produce the same tokens. Same for e.g."+-"
and"-+"
.You will need something else if you want to differentiate between
" "
and" "
.On the short test, the morse code for HEY JUDE is missing the 3 spaces required to separate HEY and JUDE. So the answer should be HEYJUDE not HEY JUDE.
On the large test the 3 spaces are present so it is correc as HEY JUDE.
If with short test, you mean Sample tests, then you must have messed it up, this is the sample test with that input:
And as you can see, the three spaces are there. Backup you code, click reset and paste it again. When reporting a problem, mention the language you're using, I assumed it's Python.
ok thanks will do
Incorrect answer for input=" ...---... -.-.-- - .... . --.- ..- .. -.-. -.- -... .-. --- .-- -. ..-. --- -..- .--- ..- -- .--. ... --- ...- . .-. - .... . .-.. .- --.. -.-- -.. --- --. .-.-.- ": expected 'SOS! THE QUICK BROWN FOX JUMPS OVER T…' to equal 'SOS! THE QUICK BROWN FOX JUMPS OVER T…'
so ummm, what's the problem here?
There is a point at the end of that sentence. I had the same problem, but when I added the point ('.-.-.-.-') to my "dictionary", it passed the test.
JavaScript Error: Incorrect answer for input=" ...---... -.-.-- - .... . --.- ..- .. -.-. -.- -... .-. --- .-- -. ..-. --- -..- .--- ..- -- .--. ... --- ...- . .-. - .... . .-.. .- --.. -.-- -.. --- --. .-.-.- ": expected 'SOS THE QUICK BROWN FOX JUMPS OVER TH…' to equal 'SOS! THE QUICK BROWN FOX JUMPS OVER T…'
I am stumped on this I figured out all the other errors but this one mentioned above.
Language selection appears to be broken...
"appears to be broken" how exactly? Looks normal to me.
Hey, I can't select a language version after seleclecting a langauge. e.g. JavaScript
Running anything I get the error:
Server Execution Error: Missing language
This definitely sounds unusual, and does not occur on my side.
#contact-mods
on Codewars Discord so we could ask more questions if needed?Thanks!
It works fine on my end too.
It doesn't happen on other Kata for me, but it also works OK in incognito. I can post screenshots here, will try to create a ticket later thanks!
Where is the preloaded Morse code table for Java?
You can access it as written in the description:
I tried, of course, before asking. What Java version contains MorseCode class? I use Java 17, there's no such class.
It doesn't come from Java itself, it comes from Preloaded file related to the kata.
Where is that preloaded file? No attachments, no links, etc.
Read this: https://docs.codewars.com/authoring/tutorials/create-first-kata/#preloaded
Here is the whole preloaded code for Java:
It's not supposed to be visible for you. All you need to know is that it exists, and roughly what it contains.
Yes, this makes it tricky to test your code locally, but it's easier for kata authors to structure their code this way. Luckily, not that many katas use preloaded like here.
Thanks a lot for all the answers!
I am usin PyCharm to work on these challenges. When I try to import the preloaded module it can't find the MORSE_CODE dict. I opened the preloaded.py file and it's complitely empty. What am I doing wrong?
No idea, but it seems a problem in your end, not with the kata.
preloaded.py
is not a library, it is a file hosted on Codewars. this is why you cannot import it on your computer.Got it TY :)
testBasicMorseDecoding Expected: is "SOS" but: was "null" Stack Trace Completed in 11ms testMoreComplexTests Expected: is "E" but: was "nullE"
it's so weird
Golang: Expected : SOS! THE QUICK BROWN FOX JUMPS OVER THELAZYDOG. to equal : SOS! THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG. I dont understood why?
Well, you returned a string with some missing spaces ("THELAZYDOG", when expected ending is "THE LAZY DOG"). You should print the input to console and try to debug it. For more information, see https://docs.codewars.com/training/troubleshooting
tnx, but i run it, right now i have another problem with next part )))
Test Results: DecodeMorse Example from description Basic bits decoding Expected : E to equal : I Completed in 0.5543ms Multiple bits per dot handling Expected : U to equal : I Completed in 0.4476ms Extra zeros handling Long messages handling Expected : S54S4HSLH to equal : THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG. Completed in 0.4355ms
Expected : HEY JUDE to equal : HEY JUDE
What language?
EDIT: OP's favorite language seems to be Go.
not a proper issue report
This comment has been hidden.
C# had a bug as in that the "Test" button only did 1 test, whereas the "Submit" button did several more. If this can't be reproduced then it might be, because I adjusted the tests, however I restarted the Kata to make sure that didn't affect the tests (and I kept the same issue, so unless the reset didnt properly reset it is bugged as I described).
Yes, this is normal, see here. When you press
Test
, only the sample tests are run. As their name implies, they are just here to showcase some tests cases to get you started. To pass a kata your code needs to be validated against the full tests (which are hidden from you until you solve the kata), this is what happens when you pressAttempt
.That was awesome! Thanks
No random tests in C#
tests are weird ☁︎︎☁︎︎
A test should include "noise". Add chars that are not dots or dashes or whitespaces
no it should not. read the description.
It think it should
No random tests in PHP
This comment has been hidden.
Your
morseAlphabet
dictionary is incomplete.Use the one provided, as the instructions say. Not a kata issue.
STDERR
codewarrior/kata
./solution.go:62:17: invalid operation: morseCode[letter] + "" (mismatched types byte and untyped string) ./solution.go:62:27: invalid argument: index letter (variable of type string) must be integer
Help
enjoyable kata
The map in Rust has a mistake, it translates morsecode for colons to commas, if you would solve this Kata wrongly by translating the characters by yourself, youd get an error like this:
Should be fixed.
This comment has been hidden.
you need to return a heap-allocated string. you are returning a static buffer of
100
chars (which is not robust, because the input string can be arbitrarily long). the tests try tofree()
the pointer you return, which crashes because it's not a pointer returned bymalloc()
.This comment has been hidden.
Because your answer has trailing spaces. Your code being wrong is not a kata issue, use
Question
label next time. Read this: https://docs.codewars.com/training/troubleshootingThis comment has been hidden.
You might be trying to decode an empty value. Pay special attention to how you are handling the empty spaces in the string
I might be doing something wrong since I've only joined yesterday, still, my code works perfectly when I manually input some morse code, however fails when I try to read input in Python. What am I doing wrong?
EOFError: EOF when reading a line
but
decode_morse('.... . -.-- .--- ..- -.. .')
Test Results:
Log
HEY JUDE
Thanks!
You don't use
input()
here, the input value is passed to your function through its argument:morse_code
The task is good thanks!)
What if there is no spaces between chars like: SOS (...---...)? The most clever solutions faild in the test case for me in Python.
It's explained in description:
It's also present in the preloaded dictionary:
morseCode.Add("...---...", "SOS");
.Hi, I can't figure out why my code isn't working (Ran it at my local enviroment and it works) - C# Can someone help me?
public static string Decode(string morseCode) { List morseCodeWords = morseCode.Trim().Split(" ").ToList(); List words = new List(); foreach (string morseCodeWord in morseCodeWords) { string word = MorseCode.Get(morseCodeWord); words.Add(word); }
string result = string.Join(" ", words); return result; }
Sorry for the bad formating, couldn't figure out how to format it.
Hello, I have run my code and i pass all the simple tests however keep failing some of the more complex ones. For some reason my code keeps switching around the characters 'E' and '.' and also 'T' and '-'
i cannot figure this out... as upon debugging my code it seems to collect all the correct characters but when i join the strings it switches them around... any help would be greatly appreciated. :D
Language: C++ Preloaded section should include required header
std::string
Fixed.
I think I got the answer but it fails all of the tests, I read other comments here saying could be extra space, but i have checked it as well and make sure no extra space, I even do a if result == 'HEY JUDE' print ('yes') at the end of the 1st test and it returns yes.
So what is wrong with my code?
This comment has been hidden.
Not a kata issue, you're passing some value that doesn't exist in the dictionary.
It doesn't contain every string passed to your function, your job is to use that dictionary and make your function to work with any string.
I still not understanding it. Help me if u can. Should I convert each individual value after returning eventually?
For Julia, why switch from three spaces to two for the complex test cases? Seems unnecessary.
Anyone knows where is de morse code table for Javascript?
There ^, you use
MORSE_CODE[codeForASingleLetterHere]
This comment has been hidden.
Does that answer your question?
I believe yes, it is. Sorry. I have read task conditions uncarefully.
Hand typing all pairs, including "SOS" and punctuation gave Me a good laugh, several times. ...and again after I've figured it is hardcoded already.
Hi, when I run my code in my IDE it works for the test cases, the only difference being that I am using a Morse Code dictionary I found somewhere else.
It seems to me there might be an issue with the test cases?
I get the following test output: '.-.-.- .-.-.-' should equal 'HEY JUDE' (The morse code is wrong) '' should equal 'A' '' should equal '7' '' should equal '$' (blank string test cases?)
Any help would be great thanks!
In Python, the default error messages are like this:
To see the input value, print it: https://docs.codewars.com/training/troubleshooting/#print-input
Use the provided dictionary here:
Thank you! I realized the MORSE_CODE dict I was using had the keys and the values switched up, 'A': '.-' instead of '.-': 'A', I made a small correction and everything ran smoothly.
So i am getting the right answer but the program doesn't say the 2 strings are equal. For example My string: E Program string: E But still says failed
NOTE: Extra spaces before or after the code have no meaning and should be ignored.
(you can't see the difference, but it's there in your result missing trailing space)
I checked it again but there is no difference. Both have no space before or after them.:(
Print the string you return and add some
*
before and after it to make sure.decode -->E <--
length = 2
Yeah I did: printf("|%s|---%zu",decode,strlen(decode));
Out:
|E|---1
So still no solution
This comment has been hidden.
Use that.
Thanks!
This comment has been hidden.
Hi, and first of all welcome to Codewars!
Your solution is really nice, but you don't need to build all these data structures yourself! You are allowed to use inbuilt ones from Python.
For example, your custom
linked_list
will work basically as Pythons[]
list will - there are various methods you can use with Python lists also to get what you want.As for your code, I tried it on e.g. input
'...-..-'
which corresponds toMORSE_CODE['...-..-'] = '$'
and your code fails due toKeyError: '...-..'
. So it seems when you look up elements in theMORSE_CODE
dict, yourcit.returnAll()
step is "chopping" the key incorrectly.Hope that helps a bit to get you started!
This comment has been hidden.
Read this: https://docs.codewars.com/training/troubleshooting/#.print-vs-return
This comment has been hidden.
Hi! Once you attempt your solution you should see which tests your solution does not pass.
This comment has been hidden.
what is broken is your code; and the tests do free your returned string
some mistakes that i see :
str(n)cat
on an uninitialized bufferCould be. Will try it out later..
All the tests are passed but, when i was attemoting it was showing the failures. How can solve this?
Your solution is basically correct - you are missing the implementation of this part of the description:
Extra spaces before or after the code have no meaning and should be ignored.
I have tested your code in the attempt - the way I was able to troubleshoot is by noticing that your results are basically correct except ' ' spaces near end of your returned final results.
As for "how you can solve this" yourself - in future, if you want to debug yourself, pay attention to such error messages in console - or, you can add
print()
statements in your code to see what it is outputting at various steps of the program. This will allow you to notice that (as in this case) you are 99% correct, just missing some small detail.I'm still stuck brother. could you please help to get pass this? the output I'm getting and the result are same but it still failed to complete the attempts.
I just retried your current solution, and I will try to illustrate what I mean - you are 99.999% close to passing!
I copied below the first result I found of some random attempts:
do you see the tiny small difference above in the 2 strings, where yours is currently different from the correct solution? You just need to modify your final returned string to deal with that tiny small difference.
As I said above, from kata Description: "Extra spaces before or after the code have no meaning and should be ignored."
I don't know how to keep the space!!! I'm coding in JavaScript, using .split among other stuff, but i think when I split I lose the space! I'm getting HEYJUDE... any suggestions?
possibly a join
This kata is a subject to deduplication process here: https://github.com/codewars/content-issues/issues/157.
Please join the discussion to help us identify duplicate kata and retire them.
This kata was decided to stay.
This comment has been hidden.
.
This comment has been hidden.
The test seems to be adding spaces to my returned string; which is causing it to fail. the begining and end of the string is laced with whitespaces. I've tried the removeSuffix and removePrefix functions but it's not helping
This is an intended challenge, not a problem with the test. Hope you can figure it out!
Time: 539ms Exit Code: 1 Test Results: Log HEY JUDE Example from description STDERR Traceback (most recent call last): File "/workspace/default/tests.py", line 16, in testAndPrint(decodeMorse('.... . -.-- .--- ..- -.. .'), 'HEY JUDE') File "/workspace/default/solution.py", line 10, in decode_morse result += MORSE_CODE[morse_code[i]] KeyError: ''
Hello! I have the right answer, what is the problem here?
No, you don't. You're passing an empty string (or a space, hard to say without proper markdown) as a key to the dictionary, that's what the error is about.
There appears to be an issue with the Java version of this Kata. The advanced test seems to have an error, causing the correct code to produce Expected: is "E" but: was "nullE"
This error occurs even when "E" is the returned String.
Probably the problem is in your code, are you doing this?
That means you should remove them from the decoded string.
I had the exact same issue and it's true, the extra spaces were the cause.
The TypeScript tests are broken for this kata. If you simply run the tests without changing anything you get this:
I don't see that, and in Typescript your function should at least return a string, what do you mean "If you simply run the tests without changing anything"?
This is the initial code:
And it's obvious it won't work and why.
No answer, closing.
Lua: There is something strange going on. It seems it expects you to return two spaces when the input has 6... or something.
I don't think this is correct.
I think there is an issue with tests in Python. My code passes all tests, but I get a STDERR message:
Time: 508ms Passed: 10 Failed: 0 Exit Code: 1
Test Results: Example from description [...] Basic Morse decoding [...] Extra zeros handling [...]
STDERR Traceback (most recent call last): File "/workspace/default/tests.py", line 30, in testAndPrint(decodeMorse(' . . '), 'E E') File "/workspace/default/solution.py", line 11, in decode_morse msg += MORSE_CODE[char] KeyError: ''
No, that's a problem with your code, not a kata issue. You're passing a key to the dictionary that doesn't exist.
Can you please elaborate further? I do not define any dictionary in my solution, which contains only a list within the function scope and returns a string. I think the definition of the problem does not request any dictionary
^ That dictionary. You're passing
''
as a key to it.Got it! Thanks mate
" ...---... -.-.-- - .... . --.- ..- .. -.-. -.- -... .-. --- .-- -. ..-. --- -..- .--- ..- -- .--. ... --- ...- . .-. - .... . .-.. .- --.. -.-- -.. --- --. .-.-.- "
2 spaces should be at the beginning of result, right? So why the expected result is "SOS! THE" instead of " SOS! THE".
If I ignore first spaces - another test fails. The one where expected result is " E E ".
I'm using C.
NOTE: Extra spaces before or after the code have no meaning and should be ignored.
Thank you
Hi, I'm working on morseDecode and I see this fault. Could you give some advise? Cannot invoke "String.isEmpty()" because "" is null
This comment has been hidden.
https://morsecode.world/international/morse2.html you need all letters + all digits + '.' + '!' + SOS
I pass all cases, but get this error. I'm struggling to correct it
Traceback (most recent call last): File "/workspace/default/tests.py", line 29, in testAndPrint(decodeMorse(' . '), 'E') File "/workspace/default/solution.py", line 16, in decode_morse wordstring += MORSE_CODE[letterstring] KeyError: ''
You're passing an empty string as key to the dictionary.
Suggesting a correction. The statement "SOS (that was first issued by Titanic)" seems to be incorrect, with reference to the following: https://timmaltin.com/2019/04/07/titanic-sos-distress-signal/ "FALSE. SOS was probably first used on 10th June 1909, about three years before the Titanic sank, by the Cunard liner SS Slavonia, when she was wrecked off the Azores."
+1 https://www.snopes.com/fact-check/titanic-first-sos/
How to add morse code to kotlin. I don't understand...
Change that
".--"
with a var that contains a single morse code.I solve everything with the IDE and then copy it here. That's why I don't understand how to do it.
Then try printing
MorseCode
here and build your own in your IDE with that.Is this what you need?
Been Stuck because of the faulty test cases. The 2 test cases in which SOS is expected from given morse Code, there is no space given between the morse code input i.e "...---..." should be given as "... --- ...". This is causing 2 tests to fail which have the words SOS in them. Please Fix the test cases as I can't move further until all the test cases are passed. This Problem is in Javascript.
You should read the description again. Please don't raise issues so lightly in the future.
I've read the description, please elaboraate what is there that you think I've missed from the description.
I won't elaborate. This is just clearly in the description. So read it again, or move on.
@akar-0 you are the reason people think coders are grumpy and unapproachable. Shame on you.
This comment has been hidden.
That means, you should removed them. And a problem with your code is not a kata issue, please read this: https://docs.codewars.com/training/troubleshooting
ok, thank you
I am using java. How can I invoke the preloaded Morse Table?
newbie
It's in the instructions. You should always read all the instructions.
This comment has been hidden.
This is a bug in your code, not a kata issue.
This comment has been hidden.
Duplicate issue.
Update to Scala 3
Approved by som1
This comment has been hidden.
Not a kata issue, there are almost 3k CPP solves.
Thanks for the reply. Looking at my code, is there something wrong in it? I've been trying to solve this since and couldn't. I'm new to kata. If you can help me, thank you.
Nobody is here to debug your code for you. Please don't raise issues so lightly in the future, see there: https://docs.codewars.com/training/troubleshooting/
This comment has been hidden.
Read the description again.
This comment has been hidden.
My code works well on Eclipse but on this site computing takes too long so tests cant be executed properly Im annoyed maybe you could raise the computing time needed for harder problems such as this one
This comment has been hidden.
This comment has been hidden.
I don't see any binary tree involved here.
Always read the description :)
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
I passed the first two cases but failed in the last case. It said " Failed asserting that two strings are equal. Expected: 'E' Actual : 'E ' " But when I try it with hardcode, it came out with the expected answer, but I'm keep getting wrong when attempt... Help...
Hi. Please say which language you are using. Also, please use markdown tags to format codes or logs, or it may be unusable (see there: https://docs.codewars.com/training/troubleshooting/#post-discourse ). For example, trailing or consecutive spaces don't display properly, but it seems your answer contains an extra trailing space.
It's alright now, I finally solved it. Thanks
seems like you have an extra whitespace character at the end of your output
I passed basic test examples and failed in "complex tests". Is there a way to check the input for each test example?
Here are the error messages I get:
Got 'undefinedEundefined', expected 'E' Got 'undefined E Eundefined', expected 'E E'
Yes: https://docs.codewars.com/training/troubleshooting/#print-input
This comment has been hidden.
I wasted a lot of time on this kata because I didn't read the instructions completely, I didn't know there was already a morse code dictionary 'MORSE_CODE[..code]', I went ahead to create my own with an object literal.
Why no to read description completely?
I'm just tryna say I could've spent a lot less time on it if I had read the instructions completely and not rushed into solving the kata
Definitely issues with the tests in PHP. Given this code: ".-.... .. ....---..." it expects the result to be "SOS".
Correct me if I'm wrong, but isn't SOS "... --- ..."?
Why are there spaces in between each letter in the initial tests (with a triple space meaning an ACTUAL space) but it's incredibly inconsistent in the final tests?
There is no such test, you're printing the input of several tests together, the tests in PHP are fine. Not a kata issue:
testBasicCases Log .-.... .. ....---... Failed asserting that two strings are equal. Expected: 'SOS' Actual : ''
I'm logging $code. And that's all I'm logging. Can you show me what I'm not understanding? The morse code for SOS isn't even in the log at all. That last portion should be HOS, no?
Use
echo( $code . "\n");
STDERR Traceback (most recent call last): File "tests.py", line 29, in testAndPrint(decodeMorse(' . '), 'E') File "/workspace/default/solution.py", line 8, in decode_morse i[x] = MORSE_CODE[i[x]] KeyError: '' ??? Time: 462ms Passed: 9Failed: 0Exit Code: 1
You're passing a non existant key to the dictionary.
stripe() solved the problem. Thanks ;)
Got '', expected 'SOS' MY CODE IS RUNNING WELL IN MY INTERPRETOR BUT THERE MAY BE SOME ERROR IN YOUR INPUT HERE ON THE WEBSITE.
This has been solved more than 24000 times in Python. I think it is safe to assume the problem is in your solution and not in the tests.
WHAT LANGUAGE DO YOU ATTEMPT
Not a kata issue, read the description again, use the provided dictionary.
I think there is an issue with the tests in Rust. Just running them without modifications on the initial code gives the following errors:
This seems to be an issue with the preloaded struct MorseDecoder. Thanks in advance for any help!
Hi. Your code has an altered set up. Currently the solution set up throws the following warnings:
This is normal, it just warns you there are unused variables in your code. I've just tried my old solution and it passes all the tests without a warning. You should do the following: save your code locally or you will lose it, make sure you have the latest version selected at the top page (Rust 1.58), push
reset
at the bottom, and you will get a clean set up, just like the one I have just used.There is no preload mod in Rust. You have to define the MORSE_CODE by yourself, I am afraid.
I think the tests have a problem! SOS input don't have spaces.
Not a kata issue; this special case is covered in the description.
Oh ok, my bad sorry
I think there's an issue with tests in Julia:
decodemorse("----. ---.. --... -.... ..... ....- ...-- ..--- .---- -----") --> "9 8 7 6 5 4 3 2 1 0"
These characters don't have 4 spaces between them, so the output should be one word per the instructions. Am I missing something?
The input (included in fixed tests) includes double spaces between each set of symbols (I don't know how to display it correctly in markdown), and the correct output is "9 8 7 6 5 4 3 2 1 0" in this case.
Hello, I Tried to solve the problem in Python my code passed all tests, but finally I have message: "STDERR Traceback (most recent call last): File "tests.py", line 29, in testAndPrint(decodeMorse(' . '), 'E') File "/workspace/default/solution.py", line 9, in decode_morse text += MORSE_CODE[char] KeyError: ''"
Can you please share your code? From this much, it appears that one of your morse code "letters" seem to be an empty string which is not a key of the dictionary: MORSE_CODE. To see the dictionary, you can run print(MORSE_CODE); this will give you the entire dictionary with the morse code: alphabet keys.
The log is clear: MORSE_CODE doesn't have a key (an entry) for empty string, so you need to find something to do in case this happens.
Thanks, I "rebooted" my mind and solved it
Hey great Kata really enjoyed this one as it went for my weakness in c++. But I was wondering what is the rule on includes if there is any. I noticed a much cleaner solution using some includes, and if there is no rule what would you say the best practice is? Either use of includes for cleaner code or muddling through the standard library to understand it better.
Does anyone knows how to use morse code dictionary provided by the author in JavaScript?
It's
MORSE_CODE[codeString]
it's not working for me 😞
hey, it worked, seems like i had some spelling error, thanks!!
Thank you!
... --- ...
This kata is all about how to organize and manipulate string in array along with undefined character. I learned a lot from this kata!
si nice
You do know the name of the function is invalid Python. It should be all lowercase and words seperated by underscores. Per the PEP 8: The Style Guide for Python Code
Fixed.
I have the same problem
I dont know why i get the following error: Got '', expected 'SOS'
Bcs when i write in my code(IDLE) SOS in morse it works and when im testing on the site it dont. (...---... --> SOS)
Same for this 'SOS! THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.' sentence in morse When i write it in morse in my IDLE it work and during the test it show only ' ! THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.'
Probably related to that?
This comment has been hidden.
You should use the Morse code they gave you:
The Morse code table is preloaded for you as a dictionary, feel free to use it:
Coffeescript/C++/Go/JavaScript/Julia/PHP/Python/Ruby/TypeScript: MORSE_CODE['.--'] C#: MorseCode.Get(".--") (returns string) F#: MorseCode.get ".--" (returns string) Elixir: @morse_codes variable (from use MorseCode.Constants). Ignore the unused variable warning for morse_codes because it's no longer used and kept only for old solutions. Elm: MorseCodes.get : Dict String String Haskell: morseCodes ! ".--" (Codes are in a Map String String) Java: MorseCode.get(".--") Kotlin: MorseCode[".--"] ?: "" or MorseCode.getOrDefault(".--", "") Racket: morse-code (a hash table) Rust: MORSE_CODE Scala: morseCodes(".--") Swift: MorseCode[".--"] ?? "" or MorseCode[".--", default: ""] C: provides parallel arrays, i.e. morse[2] == "-.-" for ascii[2] == "C" NASM: a table of pointers to the morsecodes, and a corresponding list of ascii symbols All the test strings would contain valid Morse code, so you may skip checking for errors and exceptions. In C#, tests will fail if the solution code throws an exception, please keep that in mind. This is mostly because otherwise the engine would simply ignore the tests, resulting in a "valid" solution.
how to use morse code dictionary provided by author in JavaScript?
This comment has been hidden.
It depends on the language, and it is in the description.
Just call dict as if you've already created it
got it thanks!
very inconsistent in how the morse is written. In a testcase, every letter is separated by a space, except for SOS, which is all one word "...---..." when it should be "... --- ..."
That's in the kata's description. Not an issue.
why "!" is -.-.-- ??? in google "!" is --..--
https://en.wikipedia.org/wiki/Morse_code#Symbol_representations
This Kata is much harder in F# due to the old F# version used. In later versions, it is possible to do String.Split(" ") to separate only the 3 spaces in-between words. As it stands, the logic required is more complicated for such a simple problem.
Not an issue. One day there will be an update, I guess. Until then you have to do with the available versions. How would this be an issue? Some languages are handier than others.
@akar-0 because all of these answer are sorted by difficulty. There's no point in sorting by difficulty if each answer is randomly hard in whatever language you've chosen. I understand that answers are going to be harder in some languages, but when the answer is extremely harder like this one, it should be left out IMO.
I can't figure it out why it's happening LMAO.
expected:<[]E E> but was:<[ ]E E>
I just split words when find 3 empty spaces like instruction said
There's some rule that I didn't undestand?
You should discard them.
This comment has been hidden.
I can't for the life of me figure out what I am doing wrong, and i'd really appreciate some help.
All the test PASS except for 2 tests:
got 'EE', expected 'E E and Got 'SOS!THEQUICKBROWNFOXJUMPSO VERTHELAZYD OG.', expected 'SOS! THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.'
What can I be doing wrong?
It seems you're doing something wrong with your spaces there. Read this: https://docs.codewars.com/training/troubleshooting
I printed the string, that is passed into the method and there's something wrong with the input string: "--.." should equal to z, while z is defined as "-..-" (I didnt check the other problems)
Expected: "SOS! THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG." But was: "SOS! THE QUICK BROXN FOZ JUMPS OVER THE LA Y DOG."
The rest workded with my code
bymathears, please, open another post, mention the language, read this too: https://docs.codewars.com/training/troubleshooting
Expected: is "E", but: was "nullE"
Please show the character that needs to be recoded into the letter "E".
My characters in the dictionary are as follows: morseCode.put(".", "E"); morseCode.put("·", "E")
I understood! Error in the description: "NOTE: Extra spaces before or after the code have no meaning and should be ignored."
Actually, extra spaces before and after the code HAVE meaning. So, it is necessary to write the following line at the beginning of the code: morseCode = morseCode.trim();
No, they don't, that's why you drop them in the decoded string.
in the submit tests the morse code '...---...' should be '...-- -...'
This comment has been hidden.
It's pre-provided under the name
MORSE_CODE
, as per the problem details.MORSE_CODE['.']
returns'E'
.When i type in that, i got an error saying: undefined name
This comment has been hidden.
You simply use it like that.
formatting the data correctly is the hard part..
This comment has been hidden.
This^
Yeah, even the SOS Wikipedia page linked in that very sentence proves the part in parens wrong. Kind of pathetic, not gonna lie
This doesn't affect the coding challenge and is not an issue, at most a suggestion.
Perhaps I see what you mean, akar-0, with the context of 'issue' and 'suggestion' definitions here https://docs.codewars.com/concepts/kata/discourse/
Test Failed There seems to be an error somewhere in your code. Exception message reads as follows: The type initializer for 'MorseCodeDecoder' threw an exception.
What is meen?
The problem is in your code, click reset and try again. Please mention the language when reporting an issue, and read this first: https://docs.codewars.com/training/troubleshooting
what is the syntax to use the preloaded dictionary in javascript?
It's the first one in the description's note.
Ah I saw that part, so typing MORSE_CODE['.--'] will import the dictionary? and then how do we invoke it? pardon my noobness
MORSE_CODE
is the dictionary name, you don't need to import it.Thank you, I didn't see this comment until after manually making a dictionary, but that's good to know for similar katas
How to use the preloaded dictionary in python?
I suggest test:
. .
should beE E
(i.e. some more trailing whitespaces at the end of input)Isn't the output for that should be just EE, since only 1 space between those dots instead of 3
I suppose it's doesn't metter, since trailing spaces shoud be completely ignored
It's as Galmieux said, that should be
EE
notE E
but anyway, as far as I remember, there is no such testcase at all...
This comment has been hidden.
This comment has been hidden.
It's pretty normal here on Codewars. You will get used to this feeling ;)
Besides, shorter does not always mean better.
I couldn't even get spaces instead of nulls.
This comment has been hidden.
I've written a Racket translation.
Approved by someone
This comment has been hidden.
Please do not pollute discourse pages this way. The solutions need to be submitted in the kata, they appear in the solutions tab, and that's it.
The discourse pages aim to provide help or report issues.
I pass all tests but exit code:1. Any ideas why does this happen?
Check for leading or trailing spaces in morse_code !
I mean, the test is actually "...---..." ("SOS") with no blank space in between whatsoever. If I, a human, got a message like that, I would interpret it as "3B", "S:" or "V7", much less a computer.
Not sure of the instruction was updated after your comment but... In addition to letters, digits and some punctuation, there are some special service codes, the most notorious of those is the international distress signal SOS (that was first issued by Titanic), that is coded as ···−−−···. These special codes are treated as single special characters, and usually are transmitted as separate words.
The instructions were like that long before this post.
I did not understand how to get Morse code dictionary in C#. Is there a MorseCode class in library of classes or should I write it by myself?
You should be able to type MorseCode.Get(".--") within your code to access the code dictionary. Hope that helps!
My test code works in my environment. All test cases pass however upon sumbitting its tells me output not as expected how come?
Read this: https://docs.codewars.com/training/troubleshooting
This comment has been hidden.
Check the error message, try your code with the same input:
testAndPrint(decodeMorse(' . '), 'E')
i dont understand this challenge with the morsecode,what are we suppose to do? details please thank you
This comment has been hidden.
Your code should remove those spaces.
Thanks a lot :)
This comment has been hidden.
Not a kata issue, that line is part of your code.
Could you help me with that code :) ?
My code passes all unittests with the exception of the random tests cases. In those random tests the code always cashes. not always at the same point. Error: Test crashed - caught unexpected signal 6. Stderr: free() invalid pointer.
The issue is that I cant seem to find out what is causing this condition. Tried to print all the incomming arguments but that doesn't seem to work.
Any thoughts on how to proceed? (im programming in C)
How is the variable MorseCode call in Golang? It doesn't specify and I tried with that name with no luck.
MORSE_CODE is the variable name of your dictionary/object/hashtable the morsecode in the brackets is just a placeholder for your dictionary key. took me a long time to figure that out. (If you console.log(MORSE_CODE) it will print out your dictionary.)
Thanks, that was good to know.
Hi everyone. JS Error: Got 'SOS THE QUICK BROWN FO JUMPS OVER THE LAZY DOG', expected 'SOS! THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.' I have tested two signs: "!" , "." Result: 1.Expected: '!', instead got: '' 2.Expected: '.', instead got: '' I have checked a lot of sites and it hasn't helped me. Does anyone have ideas about it?
Note how you are missing also
"X"
.Do you use the Morse dictionary provided by the author, or maybe created your own?
"X" I have fixed up. In instructions the author didn't write about dictionary for JS, so I just took table on internet.
This comment has been hidden.
This comment has been hidden.
What's wrong with the tests? From what you posted, it looks like you are returning the incorrect values. The description states: NOTE: Extra spaces before or after the code have no meaning and should be ignored. Your solution has spaces before and after the returned value.
This comment has been hidden.
is the 'SOS' test broken for python? it's the only one I'm missing.
it returns ' ', however when I manually introduce it in my program in vscode it returns SOS just as expected.
I believe it is checking for '...---...' without spaces in between each letter. When it should check for '...(space)---(space)...'
This was tricky but it was fun to solve it by myself without Linq.
This comment has been hidden.
Use the preloaded MORSE_CODE instead of using yours:
You code deletes all spaces.
This comment has been hidden.
Approved by someone
This comment has been hidden.
I've made a NASM translation for this kata, but when it came to creating tests I suddenly realized the c++ version I had solved didn't have any random tests at all.
Do other languages have random tests?
C
Thanks. I'll maybe duplicate those then.
.
This comment has been hidden.
It's hard to tell from the error message, but I can see in your code it will result in an unwanted trailing whitespace.
Ah, I should've saw that. That was my bad, thanks for pointing out :)
in pure c:
Expected: 9@?E$,A"V3:($J CV AE_ ,9SOS O718P0D3 N Submitted: 9@?E$,A"V3:($J CV AE_ ,9SOS O718P0D3 N
Expected: E Submitted: E Completed in 0.6425ms
Are you sure there are no leading/trailing spaces in your returned value?
This comment has been hidden.
"The Morse code table is preloaded for you as a dictionary, feel free to use it: Coffeescript/C++/Go/JavaScript/Julia/PHP/Python/Ruby/TypeScript: MORSE_CODE['.--']"
my language JS but how to use it? i dont know.
MORSE_CODE[codeHere]
A pigeon just said, "I love you" in morse code.
This comment has been hidden.
This comment has been hidden.
Hey, can you explain in little more details please ? I have a valid solution that works in my editor, with my own object, copied from web with Morse Code key: value pairs. But my solutions fails on the very first line of code test, I'm pretty sure that is because I have unicode key values instead ascii. Please help with this preloaded morse code object, how to acces it ?
Ya it's built into the codewars enviornment only so you may not be able to access it through the use of your own editor (VSC/Atom/etc.)
Using codewars for the different languages you can access the library using the note left by the creator. Since I primarily use JS all I did was console.log(MORSE_CODE) to view the entire object to see what was what.
I hope this helps. Here's the note the creator left for all of the different languages.
NOTE: For coding purposes you have to use ASCII characters . and -, not Unicode characters.
The Morse code table is preloaded for you as a dictionary, feel free to use it:
Coffeescript/C++/Go/JavaScript/Julia/PHP/Python/Ruby/TypeScript: MORSE_CODE['.--'] C#: MorseCode.Get(".--") (returns string) Elixir: @morse_codes variable (from use MorseCode.Constants). Ignore the unused variable warning for morse_codes because it's no longer used and kept only for old solutions. Elm: MorseCodes.get : Dict String String Haskell: morseCodes ! ".--" (Codes are in a Map String String) Java: MorseCode.get(".--") Kotlin: MorseCode[".--"] ?: "" or MorseCode.getOrDefault(".--", "") Rust: self.morse_code Scala: morseCodes(".--") Swift: MorseCode[".--"] ?? "" or MorseCode[".--", default: ""] C: provides parallel arrays, i.e. morse[2] == "-.-" for ascii[2] == "C"
This comment has been hidden.
This is either wrong or argued: https://www.golangprograms.com/go-language/constants.html
https://go.dev/doc/effective_go#mixed-caps
https://github.com/golang/go/wiki/CodeReviewComments#mixed-caps
While golint is now deprecated, it would immediately flag use of
MORSE_CODE
as inappropriate.Your own link notes at the bottom:
I’ll take the word of
github.com/golang/go
andgo.dev
documentation itself as more authoritative than an online “learn how to program” intro page. Even if this only concerns style recommendations of what should be prefered, not what must be done.This comment has been hidden.
Note that the following code fragment will cause the same behavior:
replace('.', MORSE_CODE['.'])
got it! thanks
OP solved it, closing
This comment has been hidden.
it seems that the key
'...---...'
is not in thedots_to_morse
dictionary amiriteAbsolutely the same. All tests are passed, but it displays the error above. Please notify if you solve it somehow!
You're not passing all tests, you're passing all tests up until the one that doesn't pass. Same as always, use print to find out what you did. Check your assumptions. There is a key error. Where does the key come from? Is it a valid key? Does the description say whether that is a valid key? And if it is valid, then is it defined somewhere? Who defines it, where? What things are defined? Print them out. Read the description from top to bottom to make sure nothing was missed, indeed it specifically mentions this particular key.
@Roman_Roman better if you ask about how to debug your code than to ask for the bug you both have to be figured out for you. If you are creating bugs then you'll want to be able to fix them too!
I believe there is an error with this test case. It says that the morse code word characters are seperated by space. But in this case, they are not.
@elisseiti1 read the description
You have some issue in test. My test passed, but yours not Your own tests Test Passed: Value == 'SOS'
Basic Morse decoding Test Passed Test Passed Test Passed Test Passed Test Passed Got '', expected 'SOS' Test Passed Test Passed Completed in 1ms More complex tests Test Passed Test Passed
No, you have some issue in your code.
How is it that the Lua version alone expects multiple spaces in the final sentence for the random test cases alone? That's not the way it is in the other languages.
Cool kata
How do i use this: The Morse code table is preloaded for you as a dictionary, feel free to use it:
Coffeescript/C++/Go/JavaScript/Julia/PHP/Python/Ruby/TypeScript: MORSE_CODE['.--'] ?
It is a dictionary. Google how to use dictionary/map/Object/Hash/Associative array in your language
I'm using C++, the code passes all tests but then segfaults at the end for some reason. The error I'm getting is:
UndefinedBehaviorSanitizer:DEADLYSIGNAL ==1==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0x7ffdf3af909f (pc 0x000000425b9a bp 0x000000000020 sp 0x7ffcf3af8fd0 T1) ==1==The signal is caused by a READ memory access. ==1==WARNING: invalid path to external symbolizer! ==1==WARNING: Failed to use and restart external symbolizer! #0 0x425b99 (/workspace/test+0x425b99) #1 0x429c48 (/workspace/test+0x429c48) #2 0x4279de (/workspace/test+0x4279de) #3 0x427467 (/workspace/test+0x427467) #4 0x42712b (/workspace/test+0x42712b) #5 0x42b975 (/workspace/test+0x42b975) #6 0x425e5d (/workspace/test+0x425e5d) #7 0x7fa25f5ecb96 (/lib/x86_64-linux-gnu/libc.so.6+0x21b96) #8 0x404b99 (/workspace/test+0x404b99)
UndefinedBehaviorSanitizer can not provide additional info. ==1==ABORTING
I have no idea what's happening here
https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#c-error-undefinedbehaviorsanitizer-segv-on-unknown-address-0x000000000000
Your solution crashes, not a kata issue. Your solution does not crash "at end". It passes all tests until it crashes, and then tests stop. If it would not crash, there probably would be more tests to come.
I'm using C++, and my code passes all testes, but
Extra_zeros_handling
.As output I get:
Expected: equal to E Actual:
And now I'm confused what is
Extra_zeros_handling
, because what are zeros? What is inputed?Because I tested it with:
000000000000 2242 341645 63457q4ga7ns57 e444657.b 025345362356 00000000000000000
as input, and it outputs
E
what is equals to.
in Morse.Not a kata issue. Print the input yourself with std::cout.
You returned empty string, but expected was 'E'. Without seeing input I couldn't tell why.
https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#how-can-i-see-which-input-causes-my-solution-to-fail
Okay! Thanks! I haven't thought about printing input, because I haven't seen an obvious output window, I mean console-style window. And I though
output
tab is for test results only. Thanks!Working in c++ and get this error, not sure why it is wrong:
Expected: equal to SOS! THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG. Actual: SOS! THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.
Make sure your output hasn't trailing spaces.
Yes what Chrono said and make sure you have the punctuation correct
In kotlin: The ".trim()" shouldn't be needed.
You need trim() to pass one of the tests: Given ' E E', expected 'E E'; or ' SOS...' => 'SOS'.
For 2 tests, "SOS" was written as "...---..." instead of "... --- ..."(with spaces), thus preventing the code from interpreting them as 3 seperate letters. I had to make a workaround for both these issues.
This issue is with respect to python and may be exclusive to its tests.
SOS has its own morse code. The reason for that is explained in the instructions.
Oh nevermind, I didn't notice that when going through the instructions.
Hi there!
I am trying to make this work in Go, any hints about this message?
Test Failed Log Expected : E to equal : E
This comment has been hidden.
If there weren't extra spaces, the test would pass, no?
try adding:
std::cout << "'" << your_result << "'" << "\n";
at the end of you function.exactly, hence the bug declare. the result is 'SOS! THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.' edit: was due to bug in my editor :/ B1ts was right there was a tab in the end. fixed ty :)
This comment has been hidden.
-.-.--
but you should use the preloaded code table.i use php ... i create an array and i have add the "!" key with "-.-.--" value. to the array. but i still have Expected: 'SOS! THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.', that didn't detect the "!" sign.
opps ...i did not careful read that section, thank you
something fishy about this test log : .-.... .. . can't find the ascii translation for the morse code of .-.... any advice, thanks :)
i,m using C lang btw
".-...."
is not part of a sample, fixed, or random tests generated by the C test suite. If you can provide more evidence of anything fishy in the future please provide more thorough details as in: the complete input, your output, and the expected output, thanks.The tests are not correct in Swift. The
morseCode:
label should be added in the method call. So, these should be likeXCTAssertEqual(decodeMorse(morseCode: ".... . -.-- .--- ..- -.. ."), "HEY JUDE")
Added underscore to the function definition to make it optional:
func decodeMorse(_ morseCode: String) -> String {
Click reset and try again.I've done this kata in Ruby. It doesn't work in the same tests. In one test it recieved 'SOS' but in the next same test it doesn't.
Absolutely unclear issue. We cannot help. OP is probably mistaken, and is long time inactive.
I guess that I have same issue on Ruby. In logs with print debug I see next: word => ...---... Test Passed: Value == "SOS", word => ...---... Test Passed: Value == "SOS", word => ...---... Expected: "S O S", instead got: "SOS"
You're not printing the input, you're printing a middle value, use
puts morseCode
at the start of your code.Log ...---... Test Passed: Value == "SOS" Log ... ---
... Test Passed: Value == "SOS" Log ... ---
... Expected: "S O S", instead got: "SOS"
The first one is the special case mentioned in the kata's description, the second one are three letters and the last one are three words of a single letter.
I eventually solved this, but would have appreciated seeing in the instructions that there is a 3-space separation between words but only a 2-space separation between numbers. It took me a long time to figure that out, I would have come to the solution much quicker if I'd known that when starting.
I'm not sure if it was there when you did this, but it's up there now.
testMoreComplexTests Expected: is "E" but: was " E" for java.. any suggestions??
Looks like there is an extra space before the E
In PHP 7.0 version, the final test is for the string "⎵⎵⎵.⎵⎵⎵.⎵" (where "⎵" represents a space) which returns: Expected: 'E⎵E' Actual : '⎵E⎵E'
As the string begins with 3 spaces, isn't my Actual response correct, and the Expected response wrong?
No
This comment has been hidden.
Hi, Swift translation added.
'alr approved some time ago'
Expected: is "E" but: was "nullE" help plz !!
i didn't understand your point
Print the input, check why your code is failing.
it done man thank you i was missing .trim() i didn't know it before this time (learning java by myself ) tyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
same bro for me also just " " in place of null..in more complex tests for me Expected: is "E" but: was " E"
This comment has been hidden.
This comment has been hidden.
Not a kata suggestion.
Before I did this Kata I had never really understood that Javascript arrays are actually Associative Arrays. Very helpful learning experience.