https://www.codingame.com/training/easy/prefix-code
Send your feedback or ask for help here!
Created by @chouch,validated by @amkad,@DomiKo and @Stilgart.
If you have any issues, feel free to ping them.
https://www.codingame.com/training/easy/prefix-code
Send your feedback or ask for help here!
Created by @chouch,validated by @amkad,@DomiKo and @Stilgart.
If you have any issues, feel free to ping them.
Hi, I am doing this problem in bash. I find problems by the test Inception, I am having problems by printing out things with break lines. Any suggestion?
I solved that problem. If you want to reproduce it the problem is the following: If you store a string with a break line in a variable and you try to echo, you will not display it correctly.
e.g:
export test=âasd\nXXXXXasdâ
echo $test
Output:
asd\nXXXXXasd
Solution:
export test=$âasd\nXXXXXasdâ
echo â$testâ
Output:
asd
XXXXXasd
Note here that distinction between single and double quotes is important.
I finally made it in bash. For those of you who are doing it in bash and are struggling with timeouts like me try to use less sub processes.
Hi, I work on this problem in C++. My program works for all examples, excepted with the 3rd example. In fact, the output expected is âDECODE FAIL AT INDEX 186â and I have also this, but before it I have this sentence âInvalid : extra bit at the end of the encoded textâ. I canât find from where comes this problem, if someone can help me to understand this ?
Youâre supposed to exit if it fails.
In C++ you can put the fail message in a return statement so that it stops the main function.
Something like this:
return printf(âDECODE FAIL AT INDEX %ldâ, index);
that is the problem
itâs not failing it gives the output âInvalid : extra bit at the end of the encoded textâ
I know this is quite late to the mix but the reason why it gives you that output is because the decoded string from Test 3 is exactly that message. In other words, the string still produces a simingly valid encoded output but the very last entry of the input string does not have any prefix code to use for its decoding⌠itâs effectively similar to the example given in the instructions â0000â â this gives you an (r) for the first three zeros and then an error because there is no prefix code for a single 0. What youâre doing is printing out that r!
I believe this is what @pardouin meant by saying that you need to exit/break from your code. Most likely youâre still outputting the decoded string even when there is no encoding found.
Iâm guessing this is a bit late to ask but still.
How do you detect that a decoding will fail at the first position?
I mean, how do you check that at the first position, thereâs a mistake?
(As a concept, I donât get it).
Detection at every position is the same: you compare the keys in the association table with the starting bits of the unmatched encoded string. Decoding fails if none of the keys match.
Hi,
I have a problem with the 3rd validator. This is the only validator that fails on me. I get the sentence âInvalid : extra bit at the end of the encoded textâ which is 50 chars long. After that I get decoding error at index 50. I output the sentence âDECODE FAIL AT INDEX 50â but the validator wait for âDECODE FAIL AT INDEX 186â. The problem is encoding error occurs at index 50, not 186. Anyone can help ?
Because decoding still does not fail up to index 50:
000000
1000
10101
1001
10111
00100
0011
11
10100
11
011
00010
010
(I assume you are talking about test 3 instead of validator 3 because you mention âINDEX 186â.)
Thanks, I found my mistake. I was keeping track of decoded char index instead of raw âbitâ index.
Excellent Problem to solve, appreciate doing it!