Live data from Hacker News

A way to torture an interviewer (C++, FizzBuzz)

news.ycombinator.com

61–70 of 84 posts

Re: A way to torture an interviewer (C++, FizzBuzz)

#61
post #44

Earlier quoted context omitted.

This whole point of Fizzbuzz is to see how one structures their code. Or at least ascertain that one _can_ write code in the first place.

How much structure can a fizzbuzz have exactly?

You can make it easily extendable for division by 7.

Re: A way to torture an interviewer (C++, FizzBuzz)

#62
post #38

Earlier quoted context omitted.

No, it's the address past the end of the array {'\0'}.

Mind to unpack that for me? Here's how I unpack this: ""[1] is the 0 (termination) byte. The 0 byte is then interpreted as an address -- the nil address. But what's the use of asking for the address of the null terminator? Where is that stored exactly?

The "" will define a null terminated char array to represent the string. But as it string contains no text it's a char array that only requires one byte (i.e. it contains nothing but the null termination character).

Now the first character of that char array is found here: ""[0]

The second character is found here: ""[1]

So the address of the second character is found here: &""[1]

But as the string was represented by one byte char array that second address is past the end of the string.

So it's actually an undefined address.

Re: A way to torture an interviewer (C++, FizzBuzz)

#63
post #31

Earlier quoted context omitted.

The evilest way to write `nullptr`.

it is not nullptr, it is address past \0 in "", which is an invalid address

No, the address itself is not invalid, you're just not allowed to dereference it. Pointers have to point at a valid object or, in the case of arrays, one past the end of the array. It's what `std::end` returns

Re: A way to torture an interviewer (C++, FizzBuzz)

#64
post #38

Earlier quoted context omitted.

No, it's the address past the end of the array {'\0'}.

Mind to unpack that for me? Here's how I unpack this: ""[1] is the 0 (termination) byte. The 0 byte is then interpreted as an address -- the nil address. But what's the use of asking for the address of the null terminator? Where is that stored exactly?

""[1] is not the termination byte, it's the byte after that.

Its address is taken there with &, which yields a const char*. The (char *) cast is only there to cast away const.

Re: A way to torture an interviewer (C++, FizzBuzz)

#65
post #62

Earlier quoted context omitted.

Mind to unpack that for me? Here's how I unpack this: ""[1] is the 0 (termination) byte. The 0 byte is then interpreted as an address -- the nil address. But what's the use of asking for the address of the null terminator? Where is that stored exactly?

The "" will define a null terminated char array to represent the string. But as it string contains no text it's a char array that only requires one byte (i.e. it contains nothing but the null termination character). Now the first character of that char array is found here: ""[0] The second character is found here: ""[1] So the address of the second character is found here: &""[1] But as the string was represented by…

Nit: one past end of an array is actually fine as an address.

Re: A way to torture an interviewer (C++, FizzBuzz)

#66
I would probably post the idiomatic version in my programming language. Hopefully it will spark a discussion around language design. If not, perhaps it's a sign that the company is pretty rigid, and might not be a nice place to work.

    io:println¨ {⍵ (⊂"fizz") (⊂"buzz") (⊂"fizzbuzz") %⍨ 2 (⊥⍤1) ⍉ 0 = 5 3 |⌺ ⍵} ⍳20

Re: A way to torture an interviewer (C++, FizzBuzz)

#67

You wouldn't torture him. You would just zero the probability of getting an offer. There's no SW house or colleague in his right mind that would want a developer that writes obfuscated and needlessly complex to understand code.

Fizzbuzz is a pass to the next questions. It's a way to weed out random people who have no idea about programming but for some reason came to the interview. While this code wouldn't be an instant offer, it would be a great solution in my eyes and it would follow hardest questions to qualify a candidate for senior position. That's my opinion at least. I'm making a hiring decisions in my company.

It's a great way to tell jokes, loosen up the interviewee, and get the jitters out.

Re: A way to torture an interviewer (C++, FizzBuzz)

#69
post #2

If a candidate were suggesting this as their serious FizzBuzz implementation fit for production, I'd have a hard talk with them about readability.

What implementation of FizzBuzz do you use in your production environment?

The point of fizzbuzz is to figure out if you are not a rock. If you cant figure out how to code fizzbuzz from basic 8th grade logic something is wrong.

Re: A way to torture an interviewer (C++, FizzBuzz)

#70

You wouldn't torture him. You would just zero the probability of getting an offer. There's no SW house or colleague in his right mind that would want a developer that writes obfuscated and needlessly complex to understand code.

Is consider this entertaining rather than torturous. A playful response to the mind numbing idiocy of fizzbuzz.

If someone wrote that in an interview I'd be keen to get them to explain to me exactly how it works... my C++ being a bit rusty (I mean old).
Post reply on HN