Unary - puzzle discussion

Hi,

I had the same issue (in Python 3), it was because I used strip(‘0b’) after bin(), and strip function also delete the 0 at the end (0b100110 -> 10011 ).

Maybe it could help…

Try bin(12345)[2:]

Hi,

The exercice gives the binary word of the C char as 1000 0011, but it seems to be 0x43 -> 0100 0011.

Is it because of the Chuck’s powers ? Maybe I made a mistake ?

What is your opinion ?

Thank you a lot.

1 Like

It is 7 bit ascii representation that is used here.

1 Like

Hehe thank you !

This problem just has so many problems that is isn’t even funny. They call it unary encoding, but that’s not true because we are encoding with two characters. Since there are two characters, that makes this binary encoding. It’s not the standard binary encoding that we work with, but it is binary encoding.

They are using 7-bit ASCII encoding instead of the normal 8-bit. By itself, this isn’t bad. Yet, this is a problem that’s in the easy section. Skipping every first bit in a byte isn’t something I would expect for a problem that’s in the easy section.

Then, while they state that they are using 7-bit ASCII encoding, you are also stripping all leading zeros that come before the very first one. While not that difficult for an experienced developer, wasn’t this supposed to be in the easy section.

7-bit ASCII encoding while stripping the leading zeros sounds like something that should be in a higher difficulty section. Not too much higher, but still higher. We are basically cutting this down the original message down into sub-sections based on given criteria, but we’re also throwing in binary bit extraction, 7-bit ASCII encoding, and truncation of leading zeros on top of that. Should this really be in the easy section?

4 Likes

hey,
I’ve written some code in C which gives me the right output but a bad answer (wtf ?).
Could someone pm me to check my code (it’s short) ? this would be very nice !

what does the console say?

Sortie console

Sortie standard :

0 0 00 0000 0 00

Échec

Trouvé :

0

Attendu :

0 0 00 0000 0 00

1 Like

Seems you managed to solve it. Do you remember how you managed to get this in the console? What was the issue in your code?

Coding in C++;

Managed to pass the first 3 test cases but I keep getting a segmentation fault on the 4th test case; Message from Chuck Norris.

I stored the message in a cstring array then used for and while loops to store the binary value of each char into a two dimensional array; each row contains one char’s binary value.
Somewhere around the 3rd iteration of my for loop I get a segmentation error.

To debug I used a cout message at the beginning of each loop to see that letter is stored in each array index. The array index contains all the proper chars (the full message) until the 3rd iteration at which point all the remaining chars suddenly become 1’s and 0’s

Please help!

p.s. I’d love to share some screen shots of whats happening but I guess new users are not allowed to share pictures?!

You need make that number and 7 binary digits. This number have 6. Answers should be 0100101

Your answer is 6 digits long? I see that many people’s have that issue and solution is simple, you need have answer as 7 digits long 0100101

Answer should be 7 digits long. Many people’s make mistake because they use 1 method of converting number to binary without including 0 at beginning. I mean that conversion answer begins from 1. That why short numbers like 38 have 6 digits not 7. Answer for ‘%’ should look like this 0100101. Mistake is to get 100101.
I found 2 method for converting binary numbers using fixt loop for 7 times and bit shift method
Answer = number >> 1; // shift binary method.
Loop 7 times{
If number is 1or 0, store as 1 or 0 to array[7];

}
Then You are sure that always will be 7 digits binary number.

2 Likes

Basically 4 methods:

  • use a buildin int->binary string method then padleft/rjustify with 0s
  • same as above but instead of padding, add 128 to make sure there are at least 7 digits and then slice to keep the last 7 digits
  • for k in range 6…0: n>>k&1 gives you the digits one by one
  • some languages like Python and Ruby cover binary string formating, for example in Python you can use f"{n:07b}"
1 Like

F-S thanks for a tip with using .zfill(7) :smiley:

There are special characters in the sentence from Chuck e.g. ’ which should be 010 0111 not 10 0111
Perhaps this is the issue.

Hello, I started some hours ago… after finishing the ASCII Art, but I’m really happy that I was able to do it in one “sit”. I couldn’t let this go until was done.
As many of you, I manage to do the first 3 cases (not with no problem, you know, the spaces at the end or between sets, or the addition of the following character that changes the last set of information, and the missing zeros at the front, etc), but finally when I arrived to the 4th case, I had a problem.
I was sure I was verifying the correct length of 7-bits, by adding the needed zeros at the transformed binary code… because, you know, it worked with the % case that the “translation” was giving me a 6-bits and I fixed-that!
After a lot of checking, I didn’t realized that I was doing it to the whole addition of the 7-bits codes (the whole chain, of all the “translated” characters) instead of doing it to each character “translation” before putting them all together.
I did it on Python, but I’m doing all the problems in Python and C++.
I wish you luck with this one.

3 Likes

thanks to you diliscia, I did the same mistake…