Chuck Norris puzzle discussion


#86

I have the same problem, I checked the binary sequence and everything is fine up to the "Chuck Norris’ keyboard has 2
" then after the space it doesnt read the “k” properly, I dont understand why.


#87

Is a guess, but problably you ar missing some states in your loops, take into account test 2 and 4 have more than one character, are your puting all the binary string altogether in this case?. for reference I have 2 loops: a loop that builds all the binary stream, and another loop that parse it to the chuck norris code.


#89

I am having this same problem, but I don’t understand your solution… Can you clarify?


#90

Thank you, bro!


#91

Hi guys! I’ve written a code in c# and it’s giving me a problem at the line “while(bfinal[j]==0)”, saying that the “array index is out of range”. I’ve noticed that if I make the count = 5 before running the “while(j < count)” it gives a correct output for that, which means (I think) that the loop runs incorrectly the second time and then the “while(bfinal[j]==0)” just gets into an infinite loop making j go huge. I’m having a hard time understanding why this is happening… it’s probably just some mistake I’ve failed to detect. I would appreciate if you guys could help me find where the mistake is. Here’s the code:

    string MESSAGE = Console.ReadLine();
    int size = MESSAGE.Length;
    string binary = "";
    int sizeb = 0;
    int[] bfinal = new int [500];
    int count = 0;
    string[] unary = new string [500];
    int j = 0;
    
    for (int n = 0; n < size; n++)
    {
        char letter = char.Parse(MESSAGE.Substring(n,1));
        int num = char.ToUpper(letter);
        binary = Convert.ToString(num, 2);
        sizeb = binary.Length;
        for (int i = 0; i < sizeb; i++)
        {
            int number = int.Parse(binary.Substring(i,1));
            bfinal[count] = number;
            count++;
        }
    }
    while (j < count)
    {
        if(bfinal[j]==1)
        {
            if(j==0) unary[j] = "0 0";
            if(j>0) unary[j] = " 0 0";
            j++;
            while(bfinal[j]==1)
            {
                unary[j] = "0";
                j++;
            }
        }
        if(bfinal[j]==0)
        {
            if(j==0) unary[j] = "00 0";
            if(j>0) unary[j]= " 00 0";
            j++;
            while(bfinal[j]==0)
            {
                unary[j] = "0";
                j++;
            }
        }
    }
    Console.WriteLine(string.Join("",unary));

#92

Hmm ?

while(bfinal[j]==0 && j < count)


#93

Yes, that did the trick. I didn’t know that an empty position on the array would be recognized as being “0”, so I just thought that the loop would stop without the need to add “j < count”. Now the first 2 tests are working ok but the third test ("%") says that it was supposed to output “0100101” in “unary” code instead of “100101”. I don’t know why the first 0 is requested and also don’t know how I could change the code to give that result as the “int.Parse(binary.Substring(i,1))” conversion also accepts that the binary version of 37 (decimal for %) is “100101”. Once again, any feedback on this would be much appreciated. :slightly_smiling:


#94

The input message consists of ASCII characters (7-bit). Not 6.

Add a 0 to the left of a binary won’t change its value.


#95

Thanks for the comment! I fixed that by adding “PadLeft(7,‘0’)” to the binary conversion. The third test is now working ok but strangely enough the last test (message from Chuch Norris) is still giving me “failure”.


#96

Hi there! I’ve managed to get 100% now. It seems that the usage of “ToUpper” was completely unnecessary and was ruining the final test. :slightly_smiling:


#97

The first three tests work great, but the last one does not.

Output from Chuck Norris message:

0 0 00 0000 0 0000 00 0 0 0 00 000 0 000 00 0 0 0 00 0 0 000 00 000 0 0000 00 0 0 0 00 0 0 00 00 0 0 0 00 00000 0 00 00 0 0 0000000 00 00 0 0 00 0 0 000 00 00 0 0 00 0 0 00 00 0 0 0 00 00 0 0000 00 00 0 00 00 0 0 0 00 00 0 00000 00 0 0 0 00 0 0 0000 00 00 0 0 00 0 0 00000 00 00 0 000 00 000 0 0 00 0 0 00 00 0 0 000000 00 0000 0 0000 00 00 0 0 00 0 0 00 00 00 0 0 00 000 0 0 00 00000 0 00 00 0000 0 0000 00 00 0 00 00 0 0 0 00 000000 0 0 00 00000 0 00 00 00 0 0 00 0 0 00000 00 00 0 0000 00 00 0 00 00 0 0 000 00 0 0 0 00 00 0 00 00 0000 0 00 00 0000 0 000 00 0 0 000 00 0 0 00 00 00 0 0 00 000 0 0 00 00000 0 00 00 0 0 0 00 000 0 00 00 0 0 0 00 00 0 0000 00 0 0 0 00 00 0 00 00 00 0 0 00 0 0 0 00 0 0 0 00 00000 0 000 00 0000 0 00 00 0000 0 000 00 000 0 0000 00 00 0 0 00 0 0 0 00 0 0 0 00 0 0 000 00 0

Failure
Found: “0 0 00 0000 0 0000 00 0 0 0 00 …0 0 000 00000 0 0000 00 0 0 0 00 0 0 00 00 0 0 0 00 00000 0 00”
Expected: “0 0 00 0000 0 0000 00 0 0 0 00 …0 0 000 00000 0 0000 00 0 0 0 00 0 0 00 00 0 0 0 00 00000 0 0 “

However, I could not find the pattern in the actual output that it said it ‘found’. I pasted the output into a text editor and searched for the pattern 00000 0 0000 and it’s not there.

I added a decoding algorithm. I can encode and decode any message and get perfect results.

Just wondering if anyone has an idea for the solution.


#98

I got it. One little typo.


#99

Hi !

I think there is a problem with the 4th test :

In the output, we can see :

000 00000

But it’s impossible !

Thank you in advance


#100

Maybe an extra space in the end? Maybe a null character somewhere?


#101

No. Actually, I think it’s a problem with CodinGame, because it doesn’t show the same result in both lines.


#102

You should examine your output precisely.
What language are you using?


#103

I’m using C++, and I’m just using cout. In work perfectly on my computer.
Do you want the whole code ?

EDIT: I don’t use cerr in any way


#104

That caused problems to me as well. You have to left-pad all the inputs so

1111111 -> 1111111
11111 -> 0011111
111 -> 0000111

:slightly_smiling:


#105

So basicly the main problem wa to figure out on how many bits charachters where coded in the tests?


#106

The first 3 tests work, but not the last one.
The binary conversion:
10000111101000111010111000111101011000000010011101101111111001011100101101001111001101001110000000110101111001011111001110001011011111100001111001011001000000000110100011000011110011000000001100100000000110101111001011111001111001101110100000000011000000000001100001110111011001000000000111011111010001101001111010011001010000000111001111100001100001110001111001010101110

I translate to a txt file, so finally my output is “cat $file”:
0 0 00 0000 0 0000 00 0 0 0 00 000 0 000 00 0 0 0 00 0 0 000 00 000 0 0000 00 0 0 0 00 0 0 00 00 0000000 0 0 00 00 0 000 00 0 0 00 00 0 0 0000000 00 00 0 0 00 0 0 000 00 00 0 0 00 0 0 00 00 0 0 0 00 00 0 0000 00 00 0 00 00 0 0 0 00 00 0 000 00 0000000 0 00 00 0 0 0 00 0 0 0000 00 00 0 0 00 0 0 00000 00 00 0 000 00 000 0 0 00 0 0 00 00 0 0 000000 00 0000 0 0000 00 00 0 0 00 0 0 00 00 00 0 0 00 000000000 0 00 00 0 0 0 00 000 0 00 00 0000 0 0000 00 00 0 00 00 00000000 0 00 00 00 0 0 00 00000000 0 00 00 0 0 0 00 0 0 0000 00 00 0 0 00 0 0 00000 00 00 0 0000 00 00 0 00 00 0 0 000 00 0 0 0 00 000000000 0 00 00 00000000000 0 00 00 0000 0 000 00 0 0 000 00 0 0 00 00 00 0 0 00 000000000 0 000 00 0 0 00000 00 0 0 0 00 000 0 00 00 0 0 0 00 00 0 0000 00 0 0 0 00 00 0 00 00 00 0 0 00 0 0 0 00 0000000 0 000 00 00 0 00000 00 0000 0 00 00 0000 0 000 00 000 0 0000 00 00 0 0 00 0 0 0 00 0 0 0 00 0 0 000 00 0

Failure:
Found: 0 0 00 0000 0 0000 00 0 0 0 00 … 000 00 0 0 0 00 0 0 000 00000 0 0000 00 0 0 0 00 0 0 00 00 00"
Expected: 0 0 00 0000 0 0000 00 0 0 0 00 … 000 00 0 0 0 00 0 0 000 00000 0 0000 00 0 0 0 00 0 0 00 00 0 "

But I cannot find that pattern ( 00 0 0 000 00000 ). Any clue?