4 kyu
Decode the Morse code, advanced
6,364 of 15,474jolaf
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.
One of the test cases in Python is actually incorrect: testAndPrint(decodeMorse(decodeBits('111')), 'E') It can't actually be distinguished from 'T'.
'TT' cannot be distingueshed from 'I' either. Nor can 'TTT' from 'S', 'TTT' from 'H' nor 'TTTT' from '5'.
Another test case that would catch out most submissions is 'T T'. This can be distinguished, with any transmission rate.
It's in the instructions. Not a kata issue.
In Go 1.20, one test fails but there doesnt appear to be any difference between the expected and my output. Additionally, my code prints the input text for debugging, and when I copy that input and test manually it passes. Is this an isssue with the kata or am I missing something?
Long messages handling case fails:
However when tested manually it passes without issue.
Is the trailing period missing in your answer not a difference?
In Python, sample test has the bits wrong, and not in the same format as announced by either the kata text nor as the tests of the attempt.
Could anyone hint me how to find the transmission rate?
This comment has been hidden.
The preloaded morse code dictionary (in golang) does not include punctuation used in the test cases.
Lots of transmission rate edge cases.
bad tests for python
Multiple bits per dot handling
WHY "111" supposed to be "." ? WHY???
This katas need to be reviewed!
Because:
how to convert this "10101..." to "-..-.xxxx" should i split it by 8 cause it is a digit ? or still i miss the rule ? i still dont get it, sorry
This comment has been hidden.
My code is not passing the Long messages handling test in TypeScript. expected: 'THE QUICK BROWN FOX JUMPS OVER THE LA…' to equal 'THE QUICK BROWN FOX JUMPS OVER THE LA…'
This is abbreviated, of course, but when I run the TS file, I receive: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
which seems about correct. What am I missing?
I can;t tell what is wrong with your solution without seeing your code, but I edited tests so messages are not truncated now. Run your solution again and you should be able to see where your answer is different from the expected one.
Double check for unnecessary leading or trailing spaces in your answer.
Perfect, thanks a lot, @hobovsky, I found the issue. I was missing the final dot, as the dictionary I loaded for MORSE_CODE didn't include punctuation marks.
Kinda hard, but i got it!
"111000111" should be (TT) why (I)
111= - ;000 = pause between char and char ;111 = -;
sum is (- -) '-' : 'T'
or 111 = 1 and 000 =0 it will be
1 = . ; 0 = pause between Dash or Dot 1 = . ;
sum is (..) '..' : 'I'
How can I know his intention?
Because of that.
Kinda got everything done, but I don't understand how to do a standard string check without lengthening. I'm stumped.
I am having problems with the character 'M' in Basic bits decoding. Assuming that a particular sequence of 1s is a dot as mentioned in the text, I assume that 111 is a ., therefore the time unit is 3, but instead it is not, it is actually 1. If I assume timeUnit = 3 then decodeBits("1110111") == ".0.", which doesn't make sense.
Doesn't this violate the "if you have trouble discerning if the particular sequence of 1's is a dot or a dash, assume it's a dot"?
There is only one 0 there, so the time unit is 1 and 111 is a dash, not a dot. Not a kata issue. The time unit remains constant in the whole string.
This comment has been hidden.
solution sharing != kata suggestion. Also please do not post solution in discourse
This comment has been hidden.
How could a skilled professional can transmit 60 words per minute?
I barely type at this speed 😂
Tricky kata, nice to solve, compliments.
111111
would be :
E -> '.'
when unit is 6
I -> '..'
when unit is 3
S -> '...'
when Unit is 2
in this case the diffrence not between dot and dash. and all of them would be correct. so which one is the answer?
I think this a problem. or do I have missed something?
With only that you should assume it's a dot with a time unit of 6. There are no 0s there so you can't read that as multiple dots. Not a kata issue.
I keep getting T and Gs in "Multiple bits per dot" and "Extra zeroes" tests. What could be wrong with my algorithm?
This comment has been hidden.
Exactly the same case for me:/ Found the tip in different comment :) i need to read instructions, more carefully:)
I also found a solution later. It was a very stupid mistake in the code above :)
Closing then.
Test for
'1111111111110000000000000000000000000000111111111111'
to equal'T T'
should be added to the task's tests, existing solutions often fail on it, assuming that'111111111111'
is a dot (and it's not the case when it can be both dot and dash)My solution works for everything except 'M'
if M is: 1110111
"Dot" – is 1 time unit long. Pause between dots and dashes in a character – is 1 time unit long.
Why is the pause between the two dots not 000 as the dot is smallest time unit (111)
.0. Expected: 'M', instead got: ''
This comment has been hidden.
Hi all. Please help someone who has completed the "Decode the Morse code, advanced" kata. How to connect to the Morse code class that is on the server, or how to make your own work?
This one was tough! And it was worth it! Thank you for coming up with such a nice idea!
Hi guys, could you help me? I managed to translate the binary to morse code with the "hey jude" test, but I don't understand how to determine the unit of time in each sample.
I just dont understand how 111 is equal to . and at the same time 1111111 is also equal to . it doesnt make much sense
Its explained in the description. This can happen when two test cases use different transmission rate (i.e. when one operator is clicking fast, amd another one clicking slowly).
And how can I meassure the transmission rate?
This comment has been hidden.
Did they disabled the replaceAll method for js?
It's not intentionally disabled. It's just not available... across all Codewars kata, for that matter.
replaceAll
has been introduced with Node 15, so should be available for kata updated to most recent Node version.I have passed every testcase besides in the case where it is expecting "I" and I am returning "E".
After some investigation it looks like the testcase is being run twice. First, setting bits to "1"; Second, setting bits to "101";
I seem to be getting the correct answer on the first iteration...
Here is a picture of a console log at the top of the solution where I am logging bits - https://ibb.co/hBH1RdJ
That's a problem with your code, not a kata issue, this code passes those two tests and fail the other obviously:
I found this one enjoyable for a few reasons:
1.) Why can't you provide the morse lookup method so I can better understand it? 2.) Why don't you provide all of the test bit strings so I can try to understand them in my own compiler? 3.) Your specifications for error correcting are not clear.
All of these make this challenge hard and frustrating, not because of the difficulty of the programming involved, but because of the way this challenge was structured and presented.
Hello!! I am new on Codewars. How can I view the test cases, so I can see why my code is failing? From already thank you very much
You can print any values you find relevant. See here for an example (it's in python but applies to any language capable of printing to
stdout
).Hi! I'm a little confused with description. The standard specifies that "Dot" is 1 time unit long, whereas "Dash" - 3 units. I don't understand why the example with 'HEY JUDE' ->
1100110011001100000011000000111111001100111111001111110000000000000011001111110011111100111111000000110011001111110000001111110011001100000011
contains duplicated bits for dots, dashes and pauses. Like in stead of1010101
for H character, it is11001100110011
. Does this mean that an arbitrary binary code may have a different length for time unit which represents number of bits for dot, dash and pause? Thanks in advanceYes, the point is that it's not determined how many ones or zeros constitutes one time unit.
For one test case, time unit can be
1
, and for another test case, one time unit can be11
, or11111
. So yes, a dot is one time unit, and a dash is three time units, but this means that if a time unit is three ones long, then one dot will be three ones, and one dash will be three time units, each of them three ones, what brought together makes it nine ones.Oh, now I get why some tests were failing. Thanks much for making things clear!
Oh god I am already scared of attempting this now lol
This comment has been hidden.
A problem with your code is not a kata issue, read this: https://docs.codewars.com/training/troubleshooting#print-input
This comment has been hidden.
I am in love with these Morse katas. Thank you very much for creating it, jolaf!
This comment has been hidden.
Indeed, it's a one of the most fairly appreciated katas. It makes you to delve into each word written in
Details
. Also it's way easier to solve it having the previous one solved.Spent too much time on the second task. This is amaing, nothing destroys my self esteem like these problems.
I passed every test and failed only two, I don't know what is the problem. Got 'I', expected 'M' I got this for two of them one in "basic bits decoding" and the other in "Multiple bits per dot handling".
If you can help me out I'd be really thankful.
I got the same thing.
The issue may be caused by the fact that in Morse code, the letter "M" is represented by two dashes, while the letter "I" is represented by two dots. That was the problem with my code, at the end I figured out a new solution. Hope this helps!
Loved this exercise!
As a side note, you should probably add a test case that passes only zeroes in. I was able to submit a solution that would result in a division by zero panic in such a case.
ngeri ko kanda
Hi! Spent sooo much cool time on this kata. Finally I passed all the tests except 'Long messages handling'.
"Got 'S5ES', expected 'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.'"
Can anyone advise how it can be fixed?
use the strip builtin fonction for the trailing spaces
liked the kata!! liked it better than the 6kyu one, but that was also nice!!
stared for a while when i saw "11001100........................etc" = HEY JUDE any way Hello Jude
deh ngeri ko
sorry? what did you mean?
Mangga nganggo basa Inggris, yen ora wong bakal bingung. Matur nuwun!
Is the "time unit" consistent within a single message?
Yes.
Chrono79 - Look at my comment above
Please review: C++ Fork
What is the error for the follow tests?
111 => "Dash" – is 3 time units long.
If i get only 111 how it can be 'E'?? '-' = T in morse code
https://prnt.sc/wTwKu6dQgGrJ
What is the error?
Not a kata issue.
Hi, It will be good to have similar languages support for all parts of this riddle. For example, I've completed part 1 on c++, but do not found c++ among languagues options for part 2.
Really pitty, that can not continue with that well formatted task here further.
There's a test case: "1110111" that seems pretty much impossible to translate. I ran it even through a morse translator, makes no sense. Is this expected behaviour?
Yes, the test is fine. It translate to M. Not a kata issue.
True, after this I tried again and I solved it lol. There was an issue on how I checked the transmission rate.
Hey, Does anyone know how to shorten an array of bits?
Hello lovely people,
I believe that there is a possible ambiguity of the problem itself. If the time multiplier is indeed 1: Then "111" has to be "-" and therefore "T". As it does not contain any 0 which would indicate the move to another dot or dash.
The same goes for "01110". My solution shows this as "-" -> "T". But the test says it should be an "E".
So, there is a possible problem as a program cannot know, if the "111" comes from a machine that repeats the "1" three times (time factor of 3) and therefore equates to a single "E". OR If it comes from a machine with time factor of 1, therefore the "111" being "-", thus "T".
Another possibility is that I am wrong and it is easy. :D
Please, have another possibility in your testing for this. /Cheers!
No, there isn't.
Aaaah, right. Haha. :D Thanks!
"Also if you have trouble discerning if the particular sequence of 1's is a dot or a dash, assume it's a dot."
By this logic, what's preventing someone from assuming every sequence of '111' is just a dot with extra 1s?
Theoretically,
111000111000111
, could mean...
or---
. The description suggests we assume it's...
.c# Really nobody had a problem with Execution Timed Out (12000 ms)? Average Test execution is about 2500 ms, and Attempt is failing...
There are ambiguities in test cases. For ex: is "111" a 'T' (when time unit = 1) or an 'E' (when time unit = 3)? Since we dont know what the time unit is, both interpretions are possible.
No, there isn't.
The test case is incomplete. If you transmit only the sequence of 0 and 1 of the letter T, most answers will not work properly
Gotta say calculating the transmission rate was the toughest part of the problem for me! Nice kata!!
In the case of 101, I'm having trouble understanding why this evaluates to "EE" in testing, when a single time unit of space is considered a pause between dots and dashes in a single character.
Would this not mean that 101 would be translated to ".." with no spaces, making it "I" instead of "EE"?
For instance in the Example of HEY JUDE the H is represented as 4 separate dots "11001100110011".
101 is I, not EE, you're misreading the logs.
You're totally right, Thank you!
This comment has been hidden.
For the case
1110000000111
If we consider the unit to be 3, the sequence of 7 0's will not make sence, which means we can confirm that unit is 1.
So this bit string should be translated into
T T
instead of any combination of E's (for this kata only).That means, any solution that finds the minimum length of sequences of 0's and 1's as the unit is incorrect.
This comment has been hidden.
I have so far been unable to pass the tests testBasicBitsDecoding and testMultipleBitsPerDotHandling in java, while I pass the other tests.
But why should 110110001 eveluate to "EE"? There is clearly 3 characters in this String.
The test also tells me it expects "EE" for, 111111111111001111100011111111000001111111111100111111111000000000111, which makes even less sense.(I tried to log the bits input into the methods by the test.)
I would appreciate if someone with the authority to do sp double-checked the units tests for java.
That looks like the input of several tests together. Are you sure that's the input? Could you add a carriage return/new line at the end of the printed input?
It's what I said, that's the input of several tests together. Not a kata issue.
This comment has been hidden.
It's perfectly valid? It spells '. ..' which translates to 'EI'
I'm trying to solve this problem, and I think that I like the letter "E" less and less. I failed 6 tests coz of "Expected: 'E"
But I like to challenge with this kata, it's so awesome! Thanks for this series!!
Yup it is a good kata
Seems to be missing C++, not sure if this is intentional or not because both part 1 and part 3 of this series have it.
There is no C++ version because nobody translated it. For a language to be present, there needs someone to make the translation, and someone else to approve it. There are more than 50 languages on CodeWars, and most languages are not present on all katas, whereas they could. So it's no use to make such sugestions. If you want there to be a translation in some language, you may try to write it yourself, this is very instructive moreover.
indeed. Need to revisit once someone kindly translates this into C++
I tried different ways to solve it but still don't understand 111000111 is '..' or '- -' ? Could someone explain one more time please?
According to kata description @"if you have trouble discerning if the particular sequence of 1's is a dot or a dash, assume it's a dot." in 111000111 exapmle three sequences exist with length of 3 bits, we assume that length of three is the shortest and equals to "1 time unit", thus the right answer is .. (two dots)
Two questions:
Is anyone here to explain how can we achive
from
1100110011001100000011000000111111001100111111001111110000000000000011001111110011111100111111000000110011001111110000001111110011001100000011
toHEY JUDE
I dont understand. According to the these rules shown below.
"Dot" – is 1 time unit long. "Dash" – is 3 time units long. Pause between dots and dashes in a character – is 1 time unit long. Pause between characters inside a word – is 3 time units long. Pause between words – is 7 time units long.
the standard does not specify how long that "time unit" It is mean that 110011 have multiple unit 2,and transform in 101 and ..
This comment has been hidden.
I don't get why "10001" should unumbiguously translate to ". ."
The instructions state " if you have trouble discerning if the particular sequence of 1's is a dot or a dash, assume it's a dot. " But it does not say anything for a troubling sequence of 0.
Here "000" can be a dot/dash separator with a bitrate of 3 or a letter separator with bitrate of 1 or a faulty word separator.
I see from the answers that everyone assumes a letter separator...
Besides, if the bit code does not make sense, it does not seem a good idea to fall back to an arbitrary decoding that would not make sense either. Why guessing? The program should instead gracefully fail IMO.
1 is one time unit long and 000 is three units long. That's why. The bitrate doesn't change in a single message in this kata. Go to the next one in the series for a more complex one.
This comment has been hidden.
No. Once is enough.
This comment has been hidden.
Why? 1 -
.
, 0 - pause in between, 11 --
and.-
-A
A
-
is 3 time units.Oh my god. It took me so long to realise what the description meant. I thought we were presuming that the time units for all of the dot / dash / sepeartions were uneven and you had to find their lengths given they should be in a size order (dot/dash is made of 1s but a dash will be longer), not that they will stick to the (k * "time unit"). That is so much easier...
completing the kata in ruby and coming up against this error message:
`block in decodeBits': no implicit conversion of nil into String (TypeError)
is anyone able to help? thanks
Hi. this is not an issue (= a bug in the kata). This means at some moment you try to apply a string method to something that is not a string, but is
nil
. You need some debugging to see where your code fails. Also, make a research online with the error messages you don't understand or the other terms (for examplenil
) is a good idea; most languages have their complete documentation available online, or it's very likely problems similar similar to yours have already been treated in some forum. This can help: https://docs.codewars.com/training/troubleshooting/On the other hand, this is a 4 kyu, which means it's a relatively hard kata. You are at 7 kyu level, which is a very beginner level. It's probably more reasonnable that you practice on a good amount of more basic tasks before doing this.
Yes, but an error in line 27 of the 20 I wrote. Also the program passes the test correctly
Seems like Java in-built dict for transforming morse code to letters has wrong order of keys and values, where they should be interchanged.
It does not seem to be so. Why you'd think it is?
My bad
Thought thare was a C version to play with it since I solved the first one, so I guess I have to wait
Fantastic kata! On to the next one! Thanks :)
Great to hear :), you're welcome.
Good luck with the next one, it's much tougher. :)
...---...
Log 1111111 #print(bits) -. #print(morse_code) Got 'N', expected 'E'
how can 1111111 be "E" = "."
BTW im in python
Because of that.
Thanks :)
Hi, on JS, why BigInt is not defined ? I tested in VSCode, and everything worked.
Not an issue. Your VSCode doesn't use the same Node JS version. Maybe in a future update it will be available.
Passed: 1 Failed: 0 Exit Code: 1 Why is that i pass the "submit" with an error but i still pass! KeyError: '1' it signals line 86 even though the code gets executed beyond this line
Looks like the null has been thrown
Great Kata! Word of advice - make sure you're getting the right unit of time :)
MORSE_CODE = { '.-': 'A', '-...': 'B', '-.-.': 'C', '-..': 'D', '.': 'E', '..-.': 'F', '--.': 'G', '....': 'H', '..': 'I', '.---': 'J', '-.-': 'K', '.-..': 'L', '--': 'M', '-.': 'N', '---': 'O', '.--.': 'P', '--.-': 'Q', '.-.': 'R', '...': 'S', '-': 'T', '..-': 'U', '...-': 'V', '.--': 'W', '-..-': 'X', '-.--': 'Y', '--..': 'Z', '.----': '1', '..---': '2', '...--': '3', '....-': '4', '.....': '5', '-....': '6', '--...': '7', '---..': '8', '----.': '9', '-----': '0', '--..--': ', ', '.-.-.-': '.', '..--..': '?', '-..-.': '/', '-....-': '-', '-.--.': '(', '-.--.-': ')', }
It's PRELOADED, you don't have to write it in your code omg...
if I have '11011' for example, how do I know if it is 2 dots for a word or 2 distinct words ? the first one got '..' or 'I' and the second is '. .'or 'E E' also I have a test case where I return 'I' or '..' instead of 'M' or '--', am i wrong or the test case assume it to be dash rather than dot
'11011' is not possible (at least in this kata), check again the times units part.
I did read it but the part after said the pause will be different something so I though it became invalid. ty anyway, I understand it now
I believe it shouldn't be a thing that 111 is just a "." of 3 time units and "-" not be a valid interpretation becaus it literally is 111, which is the definition of "-". There is a test case when "attempt"-ing that is literally just 111 and I interpreted it as - instead if ".", there's no clue to know it is not a "-". If i am wrong, please explain how should I know when this is the case where the time unit is 3.
In the kata description:
Not a kata issue. Use
Question
label when you don't get something.Great, now i can assume every sequence of 1s is just a dot. Thanks for the detailed explanation. I feel good now
When you have no other reference, then yes. That's what it says and what you should do.
It's a tiebreaker. When all other attempts to identify whether a pattern is dots or dashes fails, assume it's dots. That doesn't mean that all patterns are arbitrarily dots.
First of all, I apologize for my answer because I really didnt feel helped at all by your replies and I took it a bit personal. Secondly, I will explain the situation. My solution had no problem at all at identifying it as a dot or a dash, it saw it clearly as a dash, so I could not implement any sort of tie braker as you explained afterwards (that's why remarking that part of the description didn't bring any light to my concern). Furthermore, I really think it would be a good advise to find the time unit, because having so there can not be any ambiguity. Finally I want to apologize again for using sarcasm so lightly against your replies.
This is a very nice and challenging kata. I love it. Function one should take care of different time unit of each message. For example, in 1110111, the time unit is 1(single 0 in the middle), thus a dash is 3 time units long, which is '111'(or '1'* 3units). Hope this is helpful. And have fun:)
It would be nice, if it would more explicitly specfiy in the description, that time units may be different
Function decodeBits(bits), that should find out the transmission rate of the message
This comment has been hidden.
Not a kata issue but CW issue on storing solution in cache, try refreshing the page or submit another solution with an extra comment or what not
Hi, i have a problem, the description says: "The Morse code table is preloaded for you" but it seems that morseCodes is not preloaded. I am trying in Python.
error: decode += morseCodes(k) NameError: name 'morseCodes' is not defined
For Python it is
MORSE_CODE['.']
ok, solved. Now there remains the problem of the '10001' case already found by others. There is no telling if '000' is a space between characters or between dots. So it can be either 'EE' or 'I'.
read the description agn, count the number
This comment has been hidden.
Yep, im understand it, so, for example: 11111 it's dot, cuz i cant determine it dot or dash. But 111 i can determine, so why it's dot? Or this sequance should be inside zeros: 0000111000000?
No you can't, how do you know if the time unit is 1 or 3? It can be either, so, it's a dot.
3 indicates the multiplier , not the exact number
This comment has been hidden.
There is always a 1 unit space between a dot/dash and another dot/dash. There are always 3 units of space between letters. There is no "transmit a double E without space between characters". There is always space between characters. Otherwise you couldn't tell characters apart. If
..
isI
, then..
isI
. If.
isE
, then. .
isEE
. There are no spaces in the translation, only in the morse transmission.Thanks for your help and clarification @awesomead, I understood what you said, I will study my algorithm more deeply
This comment has been hidden.
Needs better tests
Please be more precise with your suggestion.
This comment has been hidden.
That test would contradict this:
Alr raised as issue
On python 3.6 one of the tests has me failing because with the input '10001' it's expecting 'I' but getting 'EE'. I'm pretty sure 'EE' is correct in this case bacause, as I understand it, in the case of '10001' the time unit would be one character meaning that the three zeros in the middle signals that you're moving to the next character but still within the same word. 'I' in morse code is '..' and 'EE' is '. .', so with a transmission rate of 1, shouldn't 'I' be '101', not '10001'?
You're confusing the logs, the expected value for
'10001'
is'EE'
and the expected value for'101'
is'I'
. You can see that with some prints, the log appears above the test result.On python 3.6, one of the test cases provides wrong input (unless I'm understanding wrong). The input is 01110 - It expects "E". But surely this should be "T", as presumably those 0's are spaces (in which case a 0 is one time unit, so a dot should be "1").If they aren't spaces, and are random, then how are you supposed to interpret this?
Edit: went through the comments some more and found someone with a similar issue. the description says to Assume it's a dot, if this occurs. "
Also if you have trouble discerning if the particular sequence of 1's is a dot or a dash, assume it's a dot
"You are supposed to read the description better :)
Not a kata issue, and no error in the test case. The zeros you specifically refer to are not spaces.
This shouldn't be about assuming it's a dot, it's for leading or trailing 0's. On the instructions there's a note:
This comment has been hidden.
You misunderstood the task.
The length of a Morse dot varies between test cases. In one test case a dot is
1
, and in another test case a dot is111
. Your task is to figure out how many ones is a dot in each given case.This one was a beast, really enjoyed it :) I had a solution working for everything except the first "Extra zeroes handling" case. When I fixed that, the second case failed and I realised I was calculating the time unit (transmission rate) incorrectly. Finally fixed that and it all works! Now I'm left looking at a regex that I don't understand even though I only wrote it a few minutes ago. Ahhhh, code.
I really don't understand, the Python algorithm that I used in the first part doesn't work here. I tried new approaches, but nothing. The Binary-to-Morse works fine, but the morse-to-string fails every time. Can anyone help me?
Have you logged the input you're getting from the decodeBits function? I initially thought I had it working but I was missing the spaces in between words!
I have found the problem. Was just a tiny (and shameful) mistake on the return of the function.
Thanks!
This comment has been hidden.
This comment has been hidden.
OP solved it, not an issue
I've spend 10 hours to solving it xD Thank you for this kata. The best one! Don't give up and try to do it by yourself!
Can anyone Help me to understand this?
Unspecified question, closing
This comment has been hidden.
Really nice kata, sadly no random tests
Thanks to the author.
Very interesting and instructive Kata!!
This comment has been hidden.
Here are some suggestions:
For the tests where you get the wrong answer, copy the input (print(input) in the beginning of your code) and the expected output value.
On your computer, add debug code to find errors, step by step, sometimes line by line.
Once done, get back to the tests, the number of passed tests should increase.
With the remaining errors or the new ones, go to step 1.
This is how I passed all the tests. Good luck!
That's what I've been doing! I said in my question that adding debug logging is exactly what I've been doing. But when I put debug logging in, the test changes, so that when I get code that should solve that problem, suddenly the problem to be solved is different and my code doesn't work. (I know this because the expected output is now completely different!)
System.Collections.Generic.KeyNotFoundException : The given key '····' was not present in the dictionary. I dont understand my codes works perfectly fine in VS (C#)
Ever seen C++ template error?
The error is literally saying that there is no element
---
in the dictonary. What else you need?How is the bits input "01110" expected to be "E", while "1110111" expected to be "M" in the test case?
In
01110
, the shortest sequence possible is of length 3 (sequence of three ones), so a dot is expected to be 3 units long. In1110111
, the shortest sequence possible is 1 (single 0 in the middle), so a dot is 1 unit long, and a dash is3 * short
.If you do not understand why the shortest sequence is 3 units and not 1 unit in the first example, you need to read description more carefully.
Should add more random tests.
This comment has been hidden.
Alr raised as issue
This comment has been hidden.
This comment has been hidden.
Really enjoyed this kata - I realized after I finished I went way overboard (rate equations, testing variables, dictionary copying), but I really appreciate how much I had to think through for this one. Understanding how to get the user's transmit speed took longer than I like to admit.
God I wish programmers could express their thoughts like a human beings
Hello, may I know if there is any C translation for this Kata? Thanks for any kind response.
In C#: System.Collections.Generic.KeyNotFoundException : The given key '' was not present in the dictionary.
I assumed that it was just whitespace or something in the output of my functions but apparently not. I have tested it with a Morse Code dictionary offline in Visual Studio, it works flawlessly. I am not sure as to why I am getting this error in the server. Can you give it a look? Thanks.
"Apparently not" how? Are you sure you do not pass some garbage value to
MorseCode.Get
? Dictionary contains following entries:I just solved the kata in C# and I enocuntered exactly the problem you mentioned when I had a bug and my
decodeBits
function. It produced invalid output, which tripped up my implementation ofdecodeMorse
in the next step. After I fixed the bug, problem went away and my solution passed without problems. Looking at the tests it also seems to be OK.I believe you have a bug somewhere in your implementation which produces empty strings as "letters". I am going to close the issue as invalid for now, and if you have more details on the exact error in the kata, feel free to re-raise it.
I am still unsure as to what caused it, but adding a !string.IsNullOrWhiteSpace seems to have fixed it. Thanks for checking it either way.
hello there! when is gonna be this kata available for c++ wizards like me ?
when some c++ wizard like you ports it to c++. :)
thank you mister !
Why would '01110' have a time unit other than 1? '0' is the maximum pause time unit in the test case, which implies pause, dash, pause. If '111' was a dot of 3 time units, then what is '0'? A third of a time unit pause??
You're in this case. After discarding the 0s, you're left with
111
and you're in this other case:This is a very tricky Kata. It is a lot of fun to work through, but has also shown me that I still have a lot to learn.
You can say that again!
Can somebody tell me why when: "console.log(decodeMorse('....'));" i'm getting "E..." should be "H" ?
You should carefully re-read description,
the standard does not specify how long that "time unit" is
meaning you have to find out what the unit size is based on input. Alsoissue
tag refers to kata's issues and yours isn't.I am trying this Kata in Kotlin but when I run the sample and the test suite, I get the map MorseCode does not reference to anything. Seems to be not loaded / there.
Kotlin initial code:
It's
MORSE_CODE
, NOTMorseCode
.
Scala translation proposed https://www.codewars.com/kumite/5f46502cf6b339002e564c41?sel=5f46502cf6b339002e564c41 Can someone approve it please ? Or let me know if there are any issues :)
Based on the description,
111
could be correctly interpreted asE
orT
. It is an edge case, but since it is one of the tests it should be addressed in the description.You mean, described? Like, in the way it's um... described, in the description? Or you maybe mean something else?
In the description (problem) it dos not give any indication on how to treat an input such as
111
therefore bothE
andT
are both valid. Of course, only one is valid in the test case, so you have to figure out what they want.It's already in the kata description.
Easy problem to fix: the provided starting code has a function decodeMorse(), but shouldn't it be named decode_morse()?
Please, mention the language you're talking about, there are many for this kata. If it is Python, this is the initial code:
As you can see the names of both functions are ok. Only the var morseCode is using camelCase and should be changed to snake_case. Now, if you talk about the kata description, yes, they are both named in camelCase and the description is shared amongst all languages.
One of the tests is '111' and it can be interpreted as both '.' and '-'.
Not an issue, read the description again:
This comment has been hidden.
i have had over 6hours on this. gosh.. now i have one error it translate 1110111 as T instead of M .. i think am getting the users speed wrong. what can i do?
T is one dash, M is two dashes.
One thing that caught me off guard with this kata is that I came under the impression that the pauses might not be uniform with the '.'s if done by an unskilled operator. So 111000111 is 'I' (two dots), but 11111100111111 is 'M' (two dashes).
The thing that is still throwing me off, though, is that 10001 is meant to map to 'EE', so it appears like the test cases allow the pauses to be longer than the dots but not vice versa?
Per se a nice task, however I found a few of the missed tests to be not very well specified beforehand.
I would like to have a deeper explanation in terms of how you want us to handle the erros that occur because of the Eindeutigkeit of bits like 111000111.
Or at least deliever some premanufactured tests that make it obvious that these are of concern to you.
Best regards!
If you look closely genug, you can find Eindeutigkeition of bits like
111000111
in the description.So, after reading the details of this kata I was unable to understand one thing. For example, I have an input "111". I have no way to distinguish a dot from a dash in this case. What do I do in this situation?
Read the description once again ;)
Thanks. My bad.
How is 111 E? I thought only 11 was a dot? anything more than 11 was a dash?
Transmission rate differs from test to test. In one test case E can be
11
, and in another test case it can be111
. It's your task to find out what it is in given test case.Also remember about this reuirement: "[...] if you have trouble discerning if the particular sequence of 1's is a dot or a dash, assume it's a dot."
but in every other test case 1 or 2 11's would equate to a dot and 3 would equate to a dash, the Kata says "Dash" – is 3 time units long.
I've just seen this highlighed as an issue many times in the issues section. I need to build in some facility to determine time limit, but i'm now going to have to build a supplimental function.
There is also an issue with one of the tests in c#(TestLongMessagesHandling) as it works in my Vis Studio, but not on the codewars kata.
Yes, kata says that dot is 1 time unit long and dash is 3 time units long, but it does not say how many 1s are in single time unit: is it
1
, or11
or111
or1111
. On the contrary, it explicitly says that time unit can differ between test cases:Your task is to find out, for every test case, how many 1s and 0s are in one time unit.
This comment has been hidden.
No, unless someone publish a translation in that language.
Hi guys,
I have struggled with this kata 2 days for now and I can't understand where I am wrong. I can't understand this thing: we have: 110011001100110000001100000011111111.... let me split this in Morse code 11 = . 00 = nothing 11 = . . . . and so on.. but when I reach the first set of "111111" I can't understand what is supposed to be coded in Morse as something else than : "-.." because we have the first 1 that lets us know that the line is connected, the next 3 of 1 indicate the "-" and the next 2 of 1 indicate 2 points: ... In the converted text there is another sequention that is "-.--" I am really glad for your help
Thanks, :)
First you have to determine the rate as mentioned in the question. In the given example, the rate is 2. Therefore, since "Dot – is 1 time unit long.", with rate = 2, Dot becomes 2 units long. (11 instead of 1). Same for "Dash – is 3 time units long.", it becomes 6 units long, i.e. 111111. So 111111 represent a dash and so on...
This took me forever to figure out after solving the initial problem. For some reason I didn't think you'd have to account for the skill of the user, despite the kata explicitly mentioning it.
How can "110110001" be expected to be EE? When the single 0 means the time unit is 1. The two sets of 11 would be neither dot nor dash, so we'll assume the are dots, as instructed.
Then there is the matter of 000 which would be a space(3 time units long) and a dot. So ".. ." == "IE"
Please help :)
When there is a doubt between a sequence of 1's been "." or "-" how do you decide that ? based on what ? The description is kinda unclear at that part
As per description:
This comment has been hidden.
fixed some time ago
In details you mention unstable coding by human operator, but i don't see any of this in tests. Allmost all soultions assume signals to be integer multipy of given signal norms and unit. Is this what author has on mind ?
yes, at least in this kata
This comment has been hidden.
Same problem here.
EDIT: Nope, I understood why
A valid 0s and 1s will always be generated and leading + trailing zeros should be removed, not an issue
Hi Guys,
I'm coding in Java and notice that following string should be considered as "E" (.) "01110", "111", "000000011100000" which is somehow logical becasue I need to handle extra zeros however in this string "000111000101010100010000000" is considered as "THE" so "000111000" in longer string is considered as T (---). Moreover this is also considered as single "E" "1111111". There is a rule if there is a doubt between (.) or (-) then I should choose (.) but in this case it is hard to guess.
Part of this kata is to find out how long a single unit of time is. In "11100010101010001" there are multiple cases of single '1' and '0', which means a single unit of time is 1 character. In "111" a single time unit is 3 characters. (though we only know this because we are supposed to assume . over -) Also notice that they in the details of this kata has an example where the time unit is 2 characters.
(I removed starting and trailing zeroes from your example since we are supposed to ignore them)
Hi! Could anyone help my query?
My code translates '111' and '111000111000111' as '.' and '...' respectively, but testing says it's wrong.
What should be the right translation?
This comment has been hidden.
This comment has been hidden.
guys, when you report things like that, be precise: that happened only in the sample tests...
anyway, corrected.
There is problem with test for Python 3.6.0
guys, when you report things like that, be precise: that happened only in the sample tests...
anyway, corrected.
This comment has been hidden.
The instructions were to ignore leading and trailing zeroes. When you do that the time signature for the first one is singular, for the second it's tripled.
This comment has been hidden.
Thanks @jdog and @ccrino .
I already understand the time step. Thanks to you both.
This comment has been hidden.
Shortest consecutive
0
s or1
s amount to a single unit, so what value single unit has exactly depends on input. Also this isn't issue (this isn't a problem with kata) but a question.Check that again.
The test extra_zeros_handling seems to expect
01110
=>.
but it seems like it could perfectly be-
as well.the idea is that since there is nothing else, you cant tell if its a - or a . (because you have nothing to compare to) so by default you need to assume its a .
The description doesn't include the name of the morse code table for some languages.
updated all the initial solutions. Removed the actual name from the description to avoide the language dependency.
What is dictionary name for Rust?
uh... maybe this?
There's a
morse_code
property in theMorseDecoder
struct.Thanks.
I passed the sample test but failed when I attempt. To try and debug I'm printing out the bits to console from decodeBits, and this one has me stumped:
Bits : 111 1111111 110011
Error: expected:<[I]> but was:<[E]>
I am not seeing how that is supposed to be an "I" which translates to ".." (Morse) or an extrapolation of "101" in binary...which is what the last line is but what about the two lines of 1's above that? Thanks
That input is for 3 different tests, the first two expect "E" and the last one expects "I", 101 at a slower speed: 110011.
Thank you for that, thought I was going nuts :)
Just like part one, would be nice to have this one in elixir
If you wish to see a kata available in some particular language, translate it yourself.
The Python test syntax in main.py uses the 'print ""' expression instead of 'print("")', even if the Kata is solved in Python 3.x. So, it raises a syntax error. Please revise. (If left as is, the kata may only be solved in Python 2.7. Any 3.x specific functions are impossible)
Done.
Still there's the same problem with Python3, there's print() expression issue in test, as well as another one i get, if needed: Traceback (most recent call last): File "main.py", line 14, in testAndPrint(decodeMorse(decodeBits('1')), 'E') File "/home/codewarrior/solution.py", line 6, in decodeMorse return ' '.join(''.join(MORSE_CODE[letter] for letter in word.split(' ')) for word in morseCode.strip().split(' ')) File "/home/codewarrior/solution.py", line 6, in return ' '.join(''.join(MORSE_CODE[letter] for letter in word.split(' ')) for word in morseCode.strip().split(' ')) File "/home/codewarrior/solution.py", line 6, in return ' '.join(''.join(MORSE_CODE[letter] for letter in word.split(' ')) for word in morseCode.strip().split(' ')) KeyError: '1'
It would be nice to see MORSE_CODE dictionary on description or in editor so that I can work on my local machine. Even after finishing the first kata of the series, I couldnt find it and was too lazy to search on google.
console.log(MORSE_CODE) will output it in test results.
Not applicable in description since it will make it language-dependent, hence hard to maintain
Can anybody exlain the example, how did we get 1100... from dots and dashes?
The rules, as stated in the kata:
How many '1' and '0's are added per dot or dash is dependent on the sampling rate. In the example, the line is sampled exactly twice per dot. Hence, a dot leads to
11
instead of just1
. With a pause between characters of a word (00
), we get1100110011001100
for....
(letterH
).Then, there is a pause for the characters inside a word which is three time units long:
000000
(6 zeros because our sampling rate is 2). A.
(11
) and another pause between characters of the same word (000000
):11000000
.11111100110011111100111111
can be split into111111
(–
),00
(pause),11
(.
),00
(pause),111111
(–
),00
(pause),111111
(–
). (and so forth)Thank you! Your answer deserves to be in the description.
This comment has been hidden.
M is -- and I is .., so I assume the M/I thing is the next test along failing after the E / T thing.
Have spent some time to figure out what is going on actually. I would rate this as a very interesting kata! Gotta try the next one.
No random tests.
This comment has been hidden.
C# translation added~
Racket translation
Hi, If there is only one character, how do you logically decide that it is a short or long one? You have nothing to compare it to. 111 can be a . with 3 unit transmission rate, or a - with one unit transmission rate. To be clear, this is not a coding question, this seems to be missing from the text of the exercise. Also, how do you actually do it?
It's already there.
Is that how you do in real life?
No idea, you'll have to ask someone who works with morse code in real life. There is a also the next kata in the series that is harder too.
@atzimler In real life you don't have to decode messages consisting of only one beep. But for the kata we have to start with trivial cases to catch basic bugs early, otherwise debugging on real-life-like cases could be too difficult. Also, in real like we can guess and we can wait until more information gets available, but for the kata we need determinism. Hence the rule for the kata - if you can't be sure, assume it's a dot.
There is a pause of 1 time unit between characters. So, one dash would look like "111", 3 dots would look like "10101". Pauses between words have 3 time units difference. So the string "e e" would look like "10001". You can assume that there is no message only containing a single character (my solution would have broken if it had that, and it was accepted).
Jaw-dropping cata!) It was extremely interesting.
Basic bits decoding Expected : E to equal : I But I saw there is "1" incoming. It decodes as ".". So "E" is right.
Basic bits decoding has many case. Maybe it's another case.
Description says that ···· · −·−− ·−−− ··− −·· · is HEY JUDE but as seen in the previous kata, there should be 3 spaces between Y and J, am I right?
Not exactly, this time:
So the code there doesn't show spaces as the previous kata. Look at the binary code below, you'll see time unit is 2 and there is a bunch of 14 zeroes that represents the space.
Looks resolved, right?
What is js MorseCode convert dictionary name ?
It's
MORSE_CODE
.thx
Function names should be in snake_case in Python.
.
Python 3 should be enabled.
Done.
Kotlin translation, would someone mind reviewing this.
Hi, did it go through review? I did part1 in Kotlin. Now I'm testing part2 and I have issues accessing MorseCode dictionary.
Hmm now I see it in the example. Where were my eyes -_-"
Approved some time ago
This comment has been hidden.
OP solved it, closing
This was a bit hard to understand at somepoint (more because of my fault than the exercise itself), but really amazing to solve. Would be great if we can solve the next version in Rust.
Thanks for the Kata!
A Python dictionary I made for running my own tests:
Python morse = (".---- ..--- ...-- ....- ..... -.... --... ---.. ----. ----- " ".- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- " ".--. --.- .-. ... - ..- ...- .-- -..- -.-- --..").split(' ') abc = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ' MORSE_CODE = dict(zip(morse, abc))
Do you realize that you can simply
print(MORSE_CODE)
and copy-paste the dictinary into your IDE from CW stdout?Hmm... I think that's the first thing I tried, and didn't work at the time for some reason. Not very familiar w/ the CW interface yet. Thanks for pointing it out :)
when bits = '1110000000111'. It's time-unit should be 1. but too many solution's is 3.
Why do you think it should it be 1?
Well, this kata is not about precise numbers and divisibility.
Some lengths may not be exact, and reasonable guessing is necessary, particularly for short message that cointain no word break (7 units) at all.
In this particular case we can't be exactly sure if this is a dash-word-dash (rate 1) or a dot-dot (rate 3) with a bit longer pause.
To make testing easier we make an assumption that if you're not sure, if this is a dot or a dash, assume it's a dot, which leads us to rate 3 in this case.
This way of thinking is important to handle real-life human made transmissions that is dealt with in the third kata of the series.
This particular edge case test was added to make sure the solution algorithm is tuned correctly for this assumption and can handle more complex tests.
I'm new to programming, so apologies in advance if this sounds dumb. I can't see how this case ('1110000000111') can be interpreted as rate 3. My reasoning goes like this: 1)Pause between words – is 7 time units long 2)if a string of zeroes is suspected of being a pause between words - it must be divisible by 7 with our rate in mind 3)if rate is 3, the pause has to be 21 zeros - not our case 4)Pause between characters inside a word – is 3 time units long 5)if a string of zeroes is suspected of being a pause between characters - it must be divisible by 3 with our rate in mind 6)if rate is 3, the pause has to be 9 zeroes - not our case 7)Pause between dots and dashes in a character – is 1 time unit long 8)if a string of zeroes is suspected of being a pause between dots and dashes - it must be equal to our rate 9)if rate is 3, the pause has to be 3 zeroes - not our case
I understand that human imperfection needs to be accounted for, however, I was under the impression that this is the main topic for the next kata in this series, while in this one the rate remains consistent for the duration of the message. If this is not the case - I've failed to find any mention of possible rate deviations in the kata's description. Am I misreading the instructions?
Please check my comment resolving this issue right above your question.
Hello,
Java version seems to be broken. Kata description warns "Caution: This kata does not currently have any known supported versions for Java. It may not be completable due to dependencies on out-dated libraries/language versions."
Preloaded MorseCode.get returns null for any input.
Please fix.
MorseCode
class.I'm having a similar problem: any string I query the library with that contains a space character (" ") returns null.
.: E ..: I . .: null
.... . -.-- .--- ..- -.. .: null
- .... . --.- ..- .. -.-. -.- -... .-. --- .-- -. ..-. --- -..- .--- ..- -- .--. ... --- ...- . .-. - .... . .-.. .- --.. -.-- -.. --- --. .-.-.-: null
no amount of resubmitting fixes the problem.
Thanks!
@Eidolonkami, that's absolutely as expected. The library is for characters, not words. And characters in Morse code do not contain spaces, only dots and dashes.
morse E = . morse T = - input: 111, time-unit = 3 output shoud be T, but I get
Expected: is "E" but: was "T"
Why is that?
If the time-unit is 3, wouldn't that
111
be a dot?Also:
Sorry but i would really like to do this in C#, how can I go about this? or can you point me towards the rules?
Here it goes: https://github.com/Codewars/codewars.com/wiki/Tutorial:-How-to-translate-a-kata
This comment has been hidden.
Vigilat, you reasoning is not taking the transmission rate of the message into account, hence the wrong conclusion.
It took me some time to understant the idea, why should I ignore zeros in this case. But now it's done. Thank you for answering.
Please include in the instructions that if you cannot determine beteween a dit and a dah it's a dit. I got stuck on that for a while.
Ex: 111 should be . not - 1 should be .
It's in there: "if you have trouble discerning if the particular sequence of 1's is a dot or a dash, assume it's a dot".
Please review Haskell translation.
This comment has been hidden.
Not a question
Coffeescript translation
I wrote the functions and passed the samples test,but failed the final.I tried to debug them in chrome,but nothing.Oh,I feel puzzle about it,pasting the origin codes here may be not suitable.How can I get some helps?
If you insist on debugging elsewhere, make sure to use Morse code table attached to this kata.
I keep passing all the tests in Python except for one on "Multiple bits per dot handling" and I can't figure out what on Earth is going on, since all other tests in the same section are completely fine. Anyone has any idea?
Time: 123ms Passed: 18 Failed: 1 Test Results: Multiple bits per dot handling Log Got '', expected 'EE' Value is not what was expected
Make sure to print everything you're trying to decode, piece by piece. Find out what is being decoded that returns empty string as a result.
Really enjoyed this one, thank you
Is this
01110
code should be translate for-
or.
?I think this is a
-
, but the test is.
result is
E
not aT
, I get.Quoting kata description: "if you have trouble discerning if the particular sequence of 1's is a dot or a dash, assume it's a dot".
Is
particular sequence
means it start with 1 ? with out consider the prefixed 0; If other, maybe I should get somebackground knowledge
.I mean a sequence of 1's without any 0's.
This comment has been hidden.
Thanks, I guess so.
This comment has been hidden.
Sorry, I'm not a JS guy, so there's not much I can help with.
But the fact that you have one start-print and two end-prints in the console suggests there's something bad in your code.
Also undefinedundefined suggests that you are merging two strings that are not yet defined at the moment, probably you're putting incorrect Morse codes into the table.
That's all I can say for now, sorry.
Ah! I see what you mean. It didn't register to me that there were two end prints. (Probably been staring at the screen for too long.) That's something. I will go look at what is going on in my code.
Thanks for the reply.
Thanks. Found the code that was the problem.
On to the third kata.
Is there any way to see the input data for the second more complex set of tests? My code passes all but three tests. I set up my own dictionary using a JS object and things seem to work.
Basic bits decoding Expected: 'EE', instead got: 'I' Expected: 'M', instead got: 'I'
Multiple bits per dot handling Expected: 'M', instead got: 'I'
I do like this Kata.
Yes, sure, you can just print input of any function of yours.
Thanks, jolaf.
I have a question.
For the example "HEY JUDE", the method decodeBits() should return "···· · −·−− ·−−− ··− −·· ·"?
If I put public static String decodeBits(String bits) { return "...."; } and then run the test, the message is "Expected: is "HEY JUDE" but: was "H""
If I put public static String decodeBits(String bits) { return "···· · −·−− ·−−− ··− −·· ·"; } and then run the test, the message is "Expected: is "HEY JUDE" but: was "null""
But i see that the tests call both MorseCodeDecoder.decodeMorse AND MorseCodeDecoder.decodeBits
Thanks.
You must call get for each morsecode part. so get("....") for "H", then get() for the "E", and so. only one sequence for one character is translated
Replace description's "amature" with "amateur"
Thanks, fixed. :)
Hello, jolaf! Very nice kata. I translated it into go: see my kumite. Hope you’ll aprove it. If something is wrong with my translations, please notice me.
Approved! Thank you for the translation!
At first attempt it pass on the sample test, when I do the attemp it pass on 7 test and fail on 8. But I cant or I dont know how to see the bits sequence on the 8 test that fail to try understend why is failing...
print the input in the console. ;)
Thanks. I start thinking that this kata is to much for me. In some case 111 is (.) in other cases is (-) and Im not understending why
Well, this kata is really not an easy one.
That's because the transmission speed of different messages is different. If the speed is fast, it could 1 is dot and 111 is dash, if it it's slow, it could be 11111 is dot and 111111111111111 is dash.
I have understood that after reread the details after my last comment, Im thinking the best way to figure out the speed, until then I will do other katas
completing the kata in ruby and coming up against this error message:
`block in decodeBits': no implicit conversion of nil into String (TypeError)
is anyone able to help? thanks
OP solved it, closing
Do you have to solve a kata before you make a translation ?
Yes. Or you have to discard the gain of honor by showing the solution.
Would be good to have a C# version of this Kata (since the first and last one in the series already do)
Yeah, I agree. You are very welcome to contribute. :)
Can someone make a c# version if so How would I go around doing that ?
^^ ditto - how?
Edit: just read the above - yeah I'm not solving this in ANOTHER language so I can add a C# version :P
I've never done any translations myself, but as far as I understand, you can insist on looking the solution in another language, and then you can translate.
This is interesting that the part 1 and 3 are translated to C# but this one still misses it.
Yeah, you are highly welcome to contribute! :)
This comment has been hidden.
Hi, you have extra spaces at the end of several results and about the last one, your algorythm fails to determine the right time unit. And about "THE QUICK BROWN..."... well, you seem to have other problems in your code too... ;)
Take a deep breathe, and dive into it... again... ;)
Thank you for your reply. I still don't understand how the trim could be causing this behaviour. I have a string as a result, which is put out in my first set of translations. As you can see, all is correctly translated, except that i produce an additional whitespace at the end. Now i take this exact result string and call trim(), as the very last operation. How could this mess up the whole result in that way? I'm not sure what i am missing. This line in decodeMorse(..) "return result.toString();" was changed to this "return result.toString().trim();"
This comment has been hidden.
You should find out the transmission rate (in other words, the number or
1
s that consitute a dot) for each message. It's different for different messages.This comment has been hidden.
Yes, I can confirm that.
Why isn't this Kata in C#? The previous one was.
Because nobody translated it to C# yet, of course. :)
Is this kata completable on Java? The example test always fails for me, even when I hard coded the wright answer (return "HEY JUDE").
Expected: is "HEY JUDE" but: was null
Yes, it's definitely completable (just checked it right now).
Note that the tests call both
MorseCodeDecoder.decodeMorse
ANDMorseCodeDecoder.decodeBits
, so you have to have some (even stub) implementations for both functions.Got "I", expected "M": Does one of the tests need revision?
Reasoning: If "I" is ".." and "M" is "--", the instructions to assume that an unknown input is a "dot" might be misleading for this test.
Thanks for the help and the great Kata.
When guessing whether a particular sequence of
1
s is a dot or a dash, one should take into account not only lengths of1
-sequences in the message, but also lengths of0
-sequences. It's important to analyze the message as a whole, not the tokens separately.101
is definitely..
, i. e.I
.111000111
looks ambiguous, it can be..
(I
) or- -
(T T
), there's no way to discern, that's why we have that rule that if you can't discern if it's a dot or a dash, assume it's a dot. But1110111
is not ambiguous at all.jolaf,
Just logged on because I realized this case. Sorry for the false alarm! Awesome that the tests are this thorough.
This comment has been hidden.
10001
can't have time unit length other than 1 (because otherwise what a single1
means?), so it'sEE
.101
also can't have time unit length other than 1, for the same reason, so it'sI
.I don't see any ambiguity here.
Could you please provide some other examples to illustrate the problem you see?
This comment has been hidden.
OP solved it, closing
Do '1' always represent dot or dash?
Yep. :)
Thanks. Could you tell me where are you from? And could you give me your contact information? Because maybe I want to ask for your help in the future.
I'm from Moscow, Russia.
The kata comments seem like a proper way of communication here. :)
Great Kata @jolaf and cool you're from Moscow. I must say you've displayed considerable patience with a LOTTTTTTTT of repeated queries. :)
who can tell me why there are an odd number of "1" in bits ? what's the meaning?
Why do you think it should be even? :)
I know it can be odd just then.One more question ? The unit long is always an integer, right?
Can you help me check my codes? I can't know where is wrong. def decodeBits(bits): # ToDo: Accept 0's and 1's, return dots, dashes and spaces dot,dash=(0,0) bits=bits.strip("0") if(bits.find("0")==-1): return "." index = bits.index("0") if(index%3!=0): dot=index dash=index3 elif(bits.find("1"index3)!=-1): dot=index dash=index3 elif(bits.find("1"(index/3))>0): dot=index/3 dash=index else: dot=index dash=index3 dd = {"1"*dot:".","1"*dash:"-"} str = "" word = bits.split("0"dot7) for i in word: letter = i.split("0"dot3) for j in letter: m = j.split("0"*dot) for k in m: str = str+dd[k] str = str+" " str = str+" " return str[:len(str)-3]
Yes, for this kata you may assume the time unit length is always an integer.
On JavaScript my code passes example test but, when I try to run the full suit test, I receive this message. "Failed to process output. It is possible that too much data was written to STDOUT." Help Please
Maybe you use too much debugging printing? I suggest turning any printing off at first to make sure it solves the problem.
You were right, it works fine now, showing what has passed and what has not. Thank you :).
This comment has been hidden.
Yes, it is supposed to pass if your solution is right.
I suggest printing your result more carefully, using some kind of hexlify (I don't know, how it's done in Ruby) or using
<pre>
tag to make sure there's no extra spaces etc. in the result.cool, i'm gonna try thanks
Good luck! :)
In the Python version, the test cases for "Extra zeros handling" are incorrect.
The test submits
01110
asbits
. With extra zeros stripped, this is111
. The sample rate here can only be one per dot. Hence, this message is three time units long, and the signal is HIGH for all three time units. This represents a dash. According to the Morse code standard, a dash is T: see https://upload.wikimedia.org/wikipedia/commons/thumb/b/b5/International_Morse_Code.svg/450px-International_Morse_Code.svg.png. These tests expect E, which is instead a dot.The same issue applies to the other test case (
bits=000000011100000
): Got T, expected E, but T is correct.There's no reason to suppose the single
111
is a dash. In fact, it could be a dash with transmission rate 1 or it could be a dot with transmission rate 3.The kata description explicitly states: "if you have trouble discerning if the particular sequence of 1's is a dot or a dash, assume it's a dot".
Therefore, it's a dot.
I can see the idea behind that, but it does break a lot of potential mathematical implementations of this problem - the greatest common divisor approach no longer works, for example. Would you be willing to reconsider that requirement (or just re-write the tests so that it doesn't matter)?
After 1211 successful completions? Sorry, no, definitely not.
The greatest common divisor approach is really not the one that was supposed to be used here. Moreover, the GCD approach would also not help you with neither
111
case, nor any other case consisting of dots only or dashes only.The main idea is this kata (as well as the previous one) are precursors to the third kata in the series, which pretents to simulate the real-life scenarios. So this kata, on purpose, stimulates the approaches that would be useful in the third kata and discourages the ones that won't be.
Closing due to no objections from the issuer.
There is no valid reason to assume that
111
is a dot.There is no trouble, because
111
directly translates to a dash.No, that's not true. You would find this out if you solve the kata.
if the input 01110 and 0 is translate as "", i think 111 should translate as "-", why you it translate as "."?
Please read the kata description carefully. Make note of the idea of time unit. Also note that, quoting, "if you have trouble discerning if the particular sequence of 1's is a dot or a dash, assume it's a dot".
I don't get why "111" is considered as an 'E', can enyone enlighten me please.
Because this is "advanced" kata :) and, quoting, 'the standard does not specify how long that "time unit" is'.
Also, quoting, 'if you have trouble discerning if the particular sequence of 1's is a dot or a dash, assume it's a dot'.
Could you please read the kata description? :)
TypeScript translation