Unary - puzzle discussion

Hello, i’m coding this puzzle in C and I am passing all 4 tests. But when I want to submit then the programm is saying that most of the tests are hardcoded. The strange thing is, when I don’t change the code and just run the tests and then submit again, it keeps changing which tests are hardcoded. Sometimes all, most of the time 25% and one time I got 50% (again without changing the code).
I also don’t know what I could have hardcoded, I think I didn’t.
Can someone help me somehow? Is there a way somebody could look at my code?

The message about hardcoding is just a hint as to why validators are different from the IDE tests, it doesn’t mean the platform considers you’re trying to hardcode a solution.
Usually when I can get a test right but not consistently, it comes down to execution speed being close to the allowed limit.

1 Like

Thx for the hint, i will try to make my code faster.

Hum I don’t understand. My code works perfectly for “CC” and else, but for chuck noris sentence it failed… I copy paste the 2 unary strings and did equals to see and it return false, even if I didn’t find where the difference is…

If it works for CC why doesn’t it work for the sentence??? ^^"

There’s a known lack of consistency with this puzzle, some validators inputs end with \n and some don’t.
There’s a chance your problem comes from that, try to handle both scenarii.

looks like
const char* MESSAGE_ARRAY = MESSAGE.c_str();
before having set the value of MESSAGE is not a good idea …

Struggling like hell for an easy puzzle. Feeling like shit lol.

1 Like

Hi everyone !

Beginner here, currently stuck on the very first part of the Chuck Norris exercise (javascript).

I have somehow obtained to convert what i wanted into binary and then into an array but I can’t find the logic for the rest.

I see that i can add a 0 for each 1 I find, and two 0 for each 0, but how do I manage when there is two 1 in a row ?

Here is my code so far :

const MESSAGE = readline();

const input = "C";

let output = "";

function convert(input, output) {

 

  for (var i = 0; i < input.length; i++) {

      const result = output += input[i].charCodeAt(0).toString(2) + " ";

      return result

  }

}

console.log(convert(input, output))

function binaryToZeros(binary) {

    

    let binaryToArray = [...binary]

    console.log(binaryToArray)

}

binaryToZeros(convert(input, output))

The number of 0s or 1s only matter for 0s repetition.
If you have ‘00011101’ for example, you want to split it into [‘000’, '111, ‘0’, ‘1’], then apply the 0/1 rule on each one, and replace each occurence by 0.
So ‘000’ --> ‘00 000’, ‘111’ -> ‘0 000’, ‘0’ -> ‘00 0’, ‘1’ -> ‘0 0’
The result would be ‘00 000 0 000 00 0 0 0’.

2 Likes

Thank you for replying. Is that then hardcoded ? How do the program know that for 111, it makes 0 000 ? Should i hardcode ‘1’ = ‘0 0’, ‘11’ =‘0 00’ and so on ?

1 Like

No you have to get your groups of 1s and 0s and replace them depending of their length.
If you’re familiar with regular expressions it’s a good use case, a group of 1s would match the regex /1+/ and a group of 0s the regex /0+/.
You can also do your grouping on the fly by keeping track of the last char parsed to know when there’s a change of group.
There are many ways to achieve that.

2 Likes

can someone help me with chuck norris puzzle

Can you describe your problem?

its a very hard puzzle to me

Hi all. My code (Kotlin, no hardcoding) works fine on all practice problems but on none of the submission problems. I had it run on custom tests for “G” and “0 0 00 000 0 000” as well as “GG” and “0 0 00 000 0 0000 00 000 0 000”, which are both green, but the corresponding tests in the submission are consistently red. Is there a way to debug what’s going wrong with the submission?

Edit: I just discovered https://www.codingame.com/forum/t/problem-with-kotlin/191028, which seems to explain my problems.
Edit2: The Kotlin compiler seems to be in good working order again. Thanks!

just use format with ‘07b’
format(ord("%"), “07b”)

Hai there.
I am trying to solve chuck norris problem. I got my code and run it. i sucessfully passed 3 test cases but i failed the last test case. i don’t know why it is happening. Please help me. I wrote my code in python.
Thanks in advance

maybe use replace function

I feel like there needs to be one more short test case before the big message. I passed the first three, but not the message, which I’m pretty sure has something to do with the space. But it’s really hard to debug because the message is so long. It would be nice if I could find that bug in a smaller test.

If the problem is with the truncated Found/Expected message in the console output then you can just copy your answer and compare it yourself with the expected one (which you can access from Test cases panel).

It should be easy to find where your encoding process went the wrong way.

1 Like