Unary - puzzle discussion

Maybe you will find the last answer of this stackoverflow thread usefull. I hope it helps.

There must be something I didnt understand… For the first test, they ask for C. In binary, its 01000011. In the game, he waits for 1000011 (without the first 0). So I needed to remove the first 0 for all exercises.

But when I submit, the 2 first exercises are wrong. Is it because he waits for the 0 now so I cant validate the test ?

The statement says:

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

So you need 7 bits per character, not 8 bits.

I did solve & submit this problem in C++ and yet i get the message “The solutions below will be available when you have solved this puzzle by yourself in the selected language.”
Yes i selected C++.
So i cannot see the solutions etc.
Anyone any idea ?

I think you have completed the code golf version of the puzzle instead of the normal version of the puzzle (which is here). You need to complete the normal version to gain access to others’ solutions.

hello,

I don’t understand this puzzle, how am I supposed to know the binary code for random characters “%”, etc ? (typescript)

You may use charCodeAt to get the ASCII code (in base 10) and then convert it to binary.

Sup guys, what is the difference between this validator and an IDE, idk why but for case 4 in IDE the result is the same as in the test case but the validator gave me an error?

Tests and validators are different. If you cannot pass the validators, that means your code is not general enough or it still contains some bugs not encountered when you run the tests.

im stuck on the % right now, getting frustrated, tried running your code in studio, would just keep running and running with no output. you had this working? currently i have this, with a whole bunch of variations, each one not being able to produce all of the successful results properly

#include
#include
#include
#include

using namespace std;

/**

  • Auto-generated code below aims at helping you parse
  • the standard input according to the problem statement.
    **/

int main() {
string message;
getline(cin, message);

// Write an answer using cout. DON’T FORGET THE “<< endl”
// To debug: cerr << “Debug messages…” << endl;

string encodedMessage;
char prevBit = '\0'; // prevBit to a non-'0' and non-'1' character

for (char c : message) {
    for (int i = 6; i >= 0; i--) {
        char bit = (c >> i) & 1; 

        if (bit == prevBit) {
            encodedMessage += "0";
        }
        else {
            if (!encodedMessage.empty()) {
                encodedMessage += " ";
            }
            encodedMessage += (bit == 0) ? "00 0" : "0 0";
            prevBit = bit;
        }
    }
}

if (encodedMessage.substr(0, 2) != "00") {
    encodedMessage = "00 " + encodedMessage;
}

cout << encodedMessage << endl;

return 0;

}

This part looks redundant to me:

if (encodedMessage.substr(0, 2) != "00") {
    encodedMessage = "00 " + encodedMessage;
}

Also,

char prevBit = '\0';

won’t work if the 7-bit ASCII code of the first character in the input string starts with a zero.

Once you fixed those issues, your code should pass all the cases.

If you haven’t tried it yet, you may use “cerr” to help you debug when solving puzzles on this website. The default code shows you the syntax to use.

By the way, your code may be properly formatted on this forum by using the </> button in the formatting toolbar.

Hope this helps.

LOL, I thought this was going to be easy but then I got snagged on the case where the converted bits are not 7 in length; thanks!

Hi, i solved yet the step int take “C” to 1000011. Do i have to invert the number and take the last number with %10? or am i overthinking it?

You don’t have to invert the number. Please read the puzzle statement, which contains two examples to explain how “C” and “CC” are encoded.

Yeah… now i Take a Loop,and take separately the Blocks of 1 and 0s… think i have it now.
Thanks

1 Like

I’m having trouble with the forth test about Chuck Norris. It seems to differ on the space character between the ‘k’ and the ‘N’. Are we supposed to skip white space, or do something different with them? When I do a space, I get a 1000000 as result so it looks like it is doing it correctly, but it still does not match the expected for the test.

You’re supposed to treat all characters, including the space character, the same way. So, the start of the message “Chuck Norris” is translated to the ASCII codes of 67, 104, 117, 99, 107, 32, 78, 111, 114, 114, 105, 115 before you further translate them to the required output. Also don’t forget the puzzle statement mentions “7 bits” per character.

encoded(CC) is not encoded(C)|encoded(C). Is that your point?

Your first sentence is correct, though I’m not sure when I made that point :sweat_smile:

I have managed to write the complete chain of ASCII code, for example for %
Found: 100101 (witch i think is right)

Can anyone orient me in the direction to encode the binary into nulls? Thanks!