Unary - puzzle discussion

#include <bitset>
// ...
bitset<8> bits(/* your char */);
// bits[/* 0 - 7 */] 
1 Like

Hi there! I have passed the first three tests, but failed with Chucky’s message. The problem seems to be in the first space character. In the ‘%’ test, I added a zero to the left to convert to 7-bits, and worked properly. But somehow this does not work with the space. However, when I try to convert a single space char, I get ‘00 0 0 0 00 00000’ from the input ‘0100000’. Any help? Thanks …

7 Likes

Problem solved, just zero-filling at the very end and not after every character …

5 Likes

I may be wrong, but in all my work with binary, there has always been 8 digits to a binary sequence. But for some godly unknown reason in this particular puzzle you chose to ignore the first bit. This had me scratching my head for a very long time because my code was correct but wasn’t passing your tests. I did not figure this out until I finally decided to look at your out files to see what you were comparing against.

Please, either correct the puzzle to use the correct number of digits, or make it VERY CLEAR in the puzzle that the binary sequence is to ignore the first bit.

7 Likes

Does anyone know what does this error means?
Aborted.
at raise.c. function __GI_raise (sig=sig@entry=6) on line 56
at abort.c. function __GI_abort () on line 89
at bitset. function std::bitset<8ul>::_M_copy_from_ptr<char, std::char_traits > (this=0x7fffffffea60, __s=0x4012d9 “C”, __len=1, __pos=0, __n=1, __zero=48 ‘0’, __one=49 ‘1’) on line 1397
at bitset. function std::bitset<8ul>::bitset ( this=0x7fffffffea60, __str=0x4012d9 “C”, __n=1, __zero=48 ‘0’, __one=49 ‘1’) on line 950
at Answer.cpp. function main () on line 44
terminate called after throwing an instance of ‘std::invalid_argument’
what(): bitset::_M_copy_from_ptr

BTW, I use “bitset<7> bitmsg(MESSAGE);” and the bitset library, I dunno what is wrong…

I used mathematical calculations do get the binary so I had to add a zero at the end if the char value was less than 64 it was a bit confusing I did it in C.

Perhaps they updated it between then and now, but the specification currently reads: “The input message consists of ASCII characters (7-bit)”

Original ASCII was a 7 bit encoding scheme. My understanding is that back when memory was scarce, if you could get away with shaving a bit off of your scheme, you went for it.

My friend’s dad once regaled me with stories of working in an old OS with 7 bit bytes for its memory allocations.I can only imagine…

After encoding the ascii int to its binary representation as string (regular all leading zeros are omitted), check the length and if it’s not 7, well the 7-bit representation, string pad fill it with zeros.

Hope that helps :wink:

2 Likes

I completed it with 100% score but i have 0/40 points and 0/2 achievments, what did I miss?

Frequently Asked Questions

100% from first attempt, as usual, in one direct pass without storage.

I have code written in powershell that works fine. There I am using the ‘\b’ character to remove unwanted spaces being added from the print command in python and getting the output that I am looking for. However in my code here on the site the \b character seems to have no effect on the code as the results were the same with and without it. Anyone have a different trick for removing the leading space from a looped print command?

Nevermind, found something that should work. In python the print command adds an obnoxious space if used within a loop. Using sys.stdout.write method will print the raw string without any assumptuous formatting. Hallelujah! :slight_smile:

It’s Chuck Norris, he doesn’t need the full 8 bits to win at life!

2 Likes

In Python 3, you can use:

print("blabla",end="")

In Python 2, you can use:

from __future__ import print_function

Thank you, I’ll have to check into that future import print_function when I get home today. Sounds like another good option!

Python 3:
My ascii -> bin looks like this:

bin(int.from_bytes(MESSAGE.encode(), 'big'))[2:]

but it seems to put extra zeros in between the characters it reads, or at least I get 1000011 0 1000011 instead of 1000011 1000011 for CC. It doesn’t just fill up for 8 Bits, since the first sequence is correct (1000011). Why’s that?

Maybe you are encoding the null character or a newline.
If you want to add extra zeroes, you can do it manually.

yeah, it looks like the function above adds zeroes between characters. I solved it by reading each character into a list and then joining them back together.

Hello,

I guess my solution was pretty close to Anna’s (mine was Java).

Firstly, the binary was calculated from each character, then merged all together into a single string and made the Chuck Norris’ conversion.

As stated in the instructions, each character should be represented by a 7-bit.

For characters that are represented with less bits, simply filled up with 0’s.

Regards,