Unary - puzzle discussion

chuck norrix

2 Likes

Y wonder the same >=/, damn headache

If you are using C++, bitset might help you.

1 Like

The validator stops at the first character that isnā€™t as expected and only shows the output so far. Itā€™s not a ā€œfinal spaceā€, there is additional output after the space.

OH my god! Thank you so much. Took me half a second to complete 100% after reading this! Thank you!

I am not certain the expected output for Test No. 3 (the %) is correct.
According to the output, it expects a 1011010 to be NorrisEncoded, but the binary representation of % is 0100101. If I put it this way, it will look different

1011010
0100101

Rest of the tests pass, so I assume, that the expected result for % test is buggy.

My code passes the 1st and 3rd tests, but 2 and 4 I get:
Process has timed out. This may mean that your solution is not optimized enough to handle some cases.

I didnā€™t think my code was that long, it just converts the ASCII text into their respective character code, then concatenates all of them into a binary string. I parse the binary string using a series of if-else statements to convert it to Chuckā€™s code. Iā€™m guessing thereā€™s a more efficient way to do this. Can somebody tell me what algorithm they used that worked?

Can anyone please take a look at my code? It passes the first three tests, but the fourth test doesnā€™t work.

[EDIT: NO FULL CODE]

Thereā€™s something weird with my code. First, i wrote it on codeblock (iā€™m working in C); works well. But when i copy it on CodinGame, it gave me 2 extra ā€˜0ā€™ et the end -_-
Iā€™ve managed to make it work, but i donā€™t understand: why? The code is the same! Where does thoses 00 comes from?

Still, the first step is done. For the second one, thought, iā€™m stuck with a segmentation fault. Since iā€™m not so good with sizes and segmentation, iā€™ll love to have you get a look at this, cause i really donā€™t see the problem:

    TUnaire[k+1]='\0';        //that was to kill the extra 0
    TailleTotale+=(k+1)*sizeof(char);  //TailleTotale=0 at the beginning of my code
    if(l==0){                             //it is the case 
        Total=malloc(TailleTotale);
        strncpy(Total, TUnaire, k); //SEGMENTATION FAULT! WHY?
    }
    else{  //i don't enter this case for now, but i guess it'll have the same problem
         Total=realloc(Total,TailleTotale);
         strcat(Total, TUnaire);
    }
    l++;
}
printf("%s\n", Total);

I really donā€™t get it. TUnaire is a char* which contain k+1 char, Total is an empty char* and i alloc it (k+1)*sizeof(char) spaceā€¦Why the first one canā€™t copy in the second? Iā€™ve even tried to copy only the first k characters of TUnaire, but that still donā€™t work.
Please help (

Itā€™s hard to say without seeing the full code, but:

Does k have a sensible value? Moreover, if TUnaire can contain k+1 chars as you wrote it, TUnaire[k+1] is one past the end of TUnaire[] (and itā€™s an error).

Check the return value of malloc (Total != NULL).

Either Total or TUnaire are not valid pointers, or k is negative or too large, or there is bug elsewhere in your code.

why string.Length is not working in the IDE but is working in monodevelop IDE, I mean, I wrote the same code as did in monodevelop but in codingame IDE does not work, example :

  • monodevelop:

         while(index != binary.Length - 1 ){
    
      	index++;
      	n = binary.ElementAt (index);
      	if(n.Equals('1'))
      		Console.Write (binary.ElementAt (index));
    
      } 
    

it works, but itā€™s not in codingame IDE.

i have a probel with the last test and i donā€™t know whatā€™s wrong -___-
chuck norrisā€™s msg is sooo strong xDD

i have the same problem xD
i donā€™t know whatā€™s wrong!! but when it came to ā€œspaceā€ it give me a problem!
like 000 and expected 00 0

i corrected my problem xD
thx me :v

I got the same problemā€¦ How did you fix it?

Pls help! :ā€™(

My program gives what the site wait in the C test: 0 0 00 0000 0 00

But the program says:
Failure
Found:
Expected: Nothing

Why??? I do not add a space to the end of the result string. What did i do wrong? Pls help! :ā€™(

Maybe you are printing some extra char. Certify that you print only the answer and you can print a new line (\n) at end.

No, iā€™m not. I asked for help in the chat, but we couldnā€™t figure it out. I sent them my code, one guy told me, itā€™s working, but in an other guy computer my code made the same error.

I tried solve the first one this way: echo(ā€œ0 0 00 0000 0 00\nā€);
But it writes the same error:

Failure
Found: " "
Expected: Nothing

This echo worked for me. If you want send me your code to test here.

echo("0 0 00 0000 0 00\n");

This code works for me.

Check you php code, it has be exactly this:

<?php echo("0 0 00 0000 0 00\n");

No new line before the <?php, and don,'t use the ?>. This way youā€™ll be sure thereā€™s no extra characters in the ouput.