Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
b0lt
Apr 29, 2005

Centripetal Horse posted:

Wouldn't this do the job?

code:
int valueToTest = 212;
int bitsSet = 0;
while (valueToTest > 0) {
        bitsSet += valueToTest & 1;
        valueToTest >>= 1;
}
Maybe I am misunderstanding, because that seems way too easy to be tripping up anyone who has developed anything more complicated than Wordpress themes.

Now I really want a thread where one of you hiring managers posts all the tests you've had huge failure rates on so we goons can take stabs at the problems.

Aside from not working for negative values, yeah, this works.

If I were giving this as an interview question, it'd be as the first stage of a multistep problem, though. How would you make this faster?

Adbot
ADBOT LOVES YOU

feedmegin
Jul 30, 2008

b0lt posted:

Aside from not working for negative values, yeah, this works.

If I were giving this as an interview question, it'd be as the first stage of a multistep problem, though. How would you make this faster?

POPCNT in SSE4, VCNT in NEON, through whatever intrinsic your compiler supports or inline assembler.
(I wouldnt have known the instruction name without looking it up but I knew it existed).

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
Use the built in popcnt r, r/m instruction or _mm_popcnt_u64(), if any language is allowed...

Walh Hara
May 11, 2012

Infinotize posted:

Not FizzBuzz, but I have yet to find a candidate that could code up a bit counter*, in any language or even pseudocode, in the ~dozen interviews where I asked that question. Maybe I should be asking FizzBuzz first.

* given a byte or an int or whatever the hell you want output how many bits in that thing are on
** these are for senior level coding positions

That actually doesn't surprise me, because I've never learned about bitwise operators at all in my studies. Java, Haskell, Graph theory, advanced algorithmic datastructures, data analsysis, bio-informatics, etc, where all considered more important than bitwise operators by my university.

feedmegin
Jul 30, 2008

Walh Hara posted:

That actually doesn't surprise me, because I've never learned about bitwise operators at all in my studies. Java, Haskell, Graph theory, advanced algorithmic datastructures, data analsysis, bio-informatics, etc, where all considered more important than bitwise operators by my university.

Then your course sucked. They are the L in ALU. Bitwise instructions are one of the few fundamental things a CPU is for. Im amazed you can go to uni for comp sci and not be given a basic course in how a CPU actually works.

Edit: you saw this guy was talking about senior-level coding positions, right? These are definitely guys who should know this stuff.

feedmegin fucked around with this message at 13:34 on Jun 19, 2016

Walh Hara
May 11, 2012

feedmegin posted:

Then your course sucked. They are the L in ALU. Bitwise instructions are one of the few fundamental things a CPU is for. Im amazed you can go to uni for comp sci and not be given a basic course in how a CPU actually works.

Well, if I had had any interest in CPU's I could probably have taken a course about that, but as I never aimed for a job where I would need to know how a CPU worked I'm not too bothered about my uni not teaching me that. I actually didn't follow a traditional comp sci course either, mine was very focused on the mathematical sides of informatics (i.e. data analysis, bio-informatics, complex algoirthms using graph theory, numerical optimisation, neural networks, time series forecasting, etc).

edit: to clarify, obviously I know what the operators and, or, xor, shift, etc mean in the context of bits. That's very simple. I just never saw the syntax and didn't know the >>= symbol (for left shift I assume?) posted in the code example above.

Walh Hara fucked around with this message at 13:33 on Jun 19, 2016

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


If none of the senior level developers you're interviewing are familiar with a topic, then you have to examine the possibility that it's just not that important in practice.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

ultrafilter posted:

If none of the senior level developers you're interviewing are familiar with a topic, then you have to examine the possibility that it's just not that important in practice.

Confirmed. I know how to use bit wise operators, and understand their function; I've needed them maybe 1-2x in the past several years.

If you're hiring for a position where they would be necessary day to day, talk to HR about filtering better or types of specific experience you'd like to see.

ToxicSlurpee
Nov 5, 2003

-=SEND HELP=-


Pillbug

ultrafilter posted:

If none of the senior level developers you're interviewing are familiar with a topic, then you have to examine the possibility that it's just not that important in practice.

I think it heavily depends on what you're working on and what the job is. In some cases you need to squeeze every bit of performance out of the hardware you can so you end up doing things like bit packing and pointer manipulation; or dealing with lower-level code than Java or C# or whatever. Same thing goes for just raw machine code; if you're programming low-level, embedded software that involves actual assembly language than you absolutely, positively, totally must be able to do bits and bytes. I'm going to go ahead and guess that a mobile app developer could probably ignore it mostly but should at least have a passing familiarity with it.

Where I went to school it was covered but wasn't considered heavily important; we took an assembly language class and an operating systems one so we would understand how computers worked but were really not expected to be wizards in the stuff. Then again I think that poo poo's cool as hell and did a ton of math and logic beyond what was expected.

feedmegin
Jul 30, 2008

ultrafilter posted:

If none of the senior level developers you're interviewing are familiar with a topic, then you have to examine the possibility that it's just not that important in practice.

Just like senior level developers in C-like languages being able to write fizz buzz is unimportant, right? Im sorry but this isn't obscure or anything, it's a basic part of the language.

smackfu
Jun 7, 2004

I feel step 2 of the interview should be "ok, how would you refactor that code so that someone who doesn't know bit wise operators could understand it?"

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

feedmegin posted:

Just like senior level developers in C-like languages being able to write fizz buzz is unimportant, right? Im sorry but this isn't obscure or anything, it's a basic part of the language.

I think you are overestimating the extent to which everybody needs to know about bitwise operators. Some people will need to know that stuff and some people just won't have been exposed to it because they've only done things at a higher level of abstraction.

There is a difference between knowledge of bitwise operators and being able to implement fizzbuzz. Fizzbuzz tests whether you can implement a (simple, unambiguous) set of behaviours; implementing a set of behaviours as requested is something pretty fundamental to working as a developer. Bitwise operators, in contrast, are a piece of trivia - have you studied them or had cause to use them before, or not? If you have, then you will know how to use them and if you haven't then you won't.

Certainly I would expect that if someone works in software development they should be able to pick up an understanding of bitwise operations rapidly, and I might have reservations about them if they struggled.

B-Nasty
May 25, 2005

smackfu posted:

I feel step 2 of the interview should be "ok, how would you refactor that code so that someone who doesn't know bit wise operators could understand it?"

Which is where my brain went right away after being primed with FizzBuzz solutions. In pseudo code:

code:
int input = XXX;
int count =0;
for(int i = 31; i >= 0; i--){

  int powerOf2 = 2^i;

 if(input % powerOf2 == 0){
    count++;
    input -= powerOf2;
  }
}

CPColin
Sep 9, 2003

Big ol' smile.
Java code:
Integer.bitCount(value);
:smug:

Klades
Sep 8, 2011

B-Nasty posted:

Which is where my brain went right away after being primed with FizzBuzz solutions. In pseudo code:

code:
int input = XXX;
int count =0;
for(int i = 31; i >= 0; i--){

  int powerOf2 = 2^i;

 if(input % powerOf2 == 0){
    count++;
    input -= powerOf2;
  }
}

Generally by refactoring you should not make things worse than they were when you got there. Raising to the power of i basically means you just made a nested loop. Plus, the code doesn't actually give the correct results, at least in C++. I set input to 12 and got 3, set it to 13 and got 1, set it to 2 and got 2.

If you really wanted to change the code so that someone who didn't know about bitwise operators could look at it and tell you what it was doing, it'd be something like this
code:
int count_bits (int number) {
  int bits = 0;

  while (number) {
    // Check for odd-ness
    if (number % 2) {
      ++bits;
    }

    // Shift all bits one to the right
    number >>= 1;
  }

  return bits;
}
If someone can't at least understand that maybe they aren't a good programmer.

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings

Klades posted:

If you really wanted to change the code so that someone who didn't know about bitwise operators could look at it and tell you what it was doing, it'd be something like this

You're dodging bitwise logical math, but you're still bitshifting. If you REALLY want to use common operators just divide by 2 to shift :v: (yes, yes, types, etc)

Centripetal Horse
Nov 22, 2009

Fuck money, get GBS

This could have bought you a half a tank of gas, lmfao -
Love, gromdul

b0lt posted:

Aside from not working for negative values, yeah, this works.

Fair point. Pretend I shifted left, and compared to the left-most bit, instead.

b0lt posted:

If I were giving this as an interview question, it'd be as the first stage of a multistep problem, though. How would you make this faster?

I'm not an optimization expert, but the only obvious improvement I see is to get rid or reduce the iterations of the loop. Depending on the language and compiler, you could rewrite that loop to take advantage of SIMD, either implicitly or explicitly. I feel like I can probably do a couple more shifts, and get rid of the loop entirely, but I don't know if I'd be able to do it properly on a whiteboard, in a minute or two, while under scrutiny. Are these candidates actually unable to write a simple bit counter, or are they falling apart at optimizing it down to microseconds? Those are two different things,. If a candidate doesn't happen to know some algorithm off the top of his head, he can go find it on Google. It seem to me that it would be much more important for him to show that he has some idea where to start.

Some people mentioned POPCNT, but I remember reading that POPCNT has (had?) some sort of issue with getting tied up waiting for registers for no good reason, which could make it very slow at times.


feedmegin posted:

Edit: you saw this guy was talking about senior-level coding positions, right? These are definitely guys who should know this stuff.

This was my thought, too. However, b0lt might have been talking about people failing to optimize, or failing at some other point in his multi-step process. I want to see what he has to say about that.


Hammerite posted:

I think you are overestimating the extent to which everybody needs to know about bitwise operators. Some people will need to know that stuff and some people just won't have been exposed to it because they've only done things at a higher level of abstraction.

You may have a point about people being able to get by without ever strictly needing bitwise operators, but to have gotten to "senior" level without being exposed to them enough to be able to shift bits down and count them off, it seems like you'd have to almost actively avoid learning about them.

PT6A
Jan 5, 2006

Public school teachers are callous dictators who won't lift a finger to stop children from peeing in my plane

B-Nasty posted:

Which is where my brain went right away after being primed with FizzBuzz solutions. In pseudo code:

code:
int input = XXX;
int count =0;
for(int i = 31; i >= 0; i--){

  int powerOf2 = 2^i;

 if(input % powerOf2 == 0){
    count++;
    input -= powerOf2;
  }
}

^ is bitwise XOR in C (and Python and Java, I know... probably a few others too) so that code will not behave as expected.

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)

Centripetal Horse posted:

I'm not an optimization expert, but the only obvious improvement I see is to get rid or reduce the iterations of the loop. Depending on the language and compiler, you could rewrite that loop to take advantage of SIMD, either implicitly or explicitly.

The fastest way I can think of using SIMD is the same way as usual, but with packed values. (And 1 -> accumulate -> shift -> loop) In software, you'd have to compare each bit I think, at least for the smallest packed value you can use.

Centripetal Horse posted:

Some people mentioned POPCNT, but I remember reading that POPCNT has (had?) some sort of issue with getting tied up waiting for registers for no good reason, which could make it very slow at times.

Yes, but iirc it's still faster and smaller than the alternative.

Found what you referenced: http://stackoverflow.com/questions/25078285/replacing-a-32-bit-loop-count-variable-with-64-bit-introduces-crazy-performance

dougdrums fucked around with this message at 03:54 on Jun 20, 2016

Contra Duck
Nov 4, 2004

#1 DAD

quote:

You may have a point about people being able to get by without ever strictly needing bitwise operators, but to have gotten to "senior" level without being exposed to them enough to be able to shift bits down and count them off, it seems like you'd have to almost actively avoid learning about them.

It's not because they've never seen them, it's because they haven't needed them for 10+ years. Skills atrophy if you don't use them and if someone's hasn't had to use a bitshift operator since some class they took in 1998 then yeah they're likely to have forgotten how all that stuff works. It's not a hard question, but at the same time I'd expect a fresh graduate to give me a better answer to that than the guy who's been a front-end dev for the past decade just because the grad has been exposed to it more recently.

Infinotize
Sep 5, 2003

Centripetal Horse posted:

Are these candidates actually unable to write a simple bit counter?

Yeah, that's what I'm talking about. This thread would pass with flying colors. It's supposed to be a 'warm up' for some follow ups like, what if the input is a much longer bit/byte array (no single popcount cheaters), what if it's going to be called a bazillion times, what kind of caching would/could you do, are there any tradeoffs to make, etc. I don't even really have a "right" answer in mind, I want to see some fog on a mirror code and then talk about some stuff.

We can even do it in python...
code:
def count_on_bits(num):
    bits = 0
    while num > 0:
        bits += num & 0x1
        num >>= 1
    return bits
I was interviewing people for an ops position a while ago. Much less stringent on coding and mainly the candidates were interviewed by our ops folks on more ops-y things, but I was the "coding" interview. The stumper was remove duplicates from a list.

Centripetal Horse
Nov 22, 2009

Fuck money, get GBS

This could have bought you a half a tank of gas, lmfao -
Love, gromdul

dougdrums posted:

Yes, but iirc it's still faster and smaller than the alternative.

Found what you referenced: http://stackoverflow.com/questions/25078285/replacing-a-32-bit-loop-count-variable-with-64-bit-introduces-crazy-performance

Yeah, that sounds like the issue I remember reading. I didn't read through that whole thing, just now, but you might be right that it's still faster than other methods, even with the register problem.


Contra Duck posted:

It's not because they've never seen them, it's because they haven't needed them for 10+ years. Skills atrophy if you don't use them and if someone's hasn't had to use a bitshift operator since some class they took in 1998 then yeah they're likely to have forgotten how all that stuff works. It's not a hard question, but at the same time I'd expect a fresh graduate to give me a better answer to that than the guy who's been a front-end dev for the past decade just because the grad has been exposed to it more recently.

That's a fair point, although I can't imagine going ten years of programming without having a need for, or at least a solid use case for, bitwise operations.


Infinotize posted:

Yeah, that's what I'm talking about. This thread would pass with flying colors. It's supposed to be a 'warm up' for some follow ups like, what if the input is a much longer bit/byte array (no single popcount cheaters), what if it's going to be called a bazillion times, what kind of caching would/could you do, are there any tradeoffs to make, etc. I don't even really have a "right" answer in mind, I want to see some fog on a mirror code and then talk about some stuff.

Hm. Guess I got you mixed up with b0lt.

When you talk about caching, do you mean in software, or making smart use of CPU caching? I don't know enough about hardware caching to make particularly good decisions, there. What are some solutions that would appeal to you? Like, my first though to handling arrays of data is to use pointer arithmetic, but I'm not sure there's any advantage to that with modern compilers.


Infinotize posted:

I was interviewing people for an ops position a while ago. Much less stringent on coding and mainly the candidates were interviewed by our ops folks on more ops-y things, but I was the "coding" interview. The stumper was remove duplicates from a list.

What would you say to, "Cram them into the language's equivalent of a hash map or associative array?" Is that another invitation for a discussion on optimization?

I am pretty curious about all of this. I've never been asked these sorts of questions in an interview.

tazjin
Jul 24, 2015


My weirdest coding interview was from the interviewer's perspective. This dude was basically applying for a sysadmin position and once I started asking him light technical questions he escalated gradually into actual insanity.

Quotes involved some things like:

quote:

What is DNS?
- It's all a part of the CPU and its registers, there's infinitely many of them you know and it's all Assembly at the bottom.

OK. At this point I knew he was just gonna say random words, but I don't like ending an interview after 10 minutes so I wanted to give him a few more minutes just to make it seem nicer.

quote:

Can you explain roughly what happens during a TLS handshake?
- It's all in the CPU registers, but they aren't real. They're ... it's all in your head. Computers are an illusion[...]

And from there he went on a crazy rant about illusions and virtual reality and everything stopped making sense. I didn't know what to say so I just let him talk for about 20 minutes before thanking him for his time.

I meet the guy at meetups in the city sometimes and usually just pretend that nothing happened.

Workaday Wizard
Oct 23, 2009

by Pragmatica
stay safe schizo interviewee

feedmegin
Jul 30, 2008

Centripetal Horse posted:

I'm not an optimization expert, but the only obvious improvement I see is to get rid or reduce the iterations of the loop.

My other thought if popcnt etc aren't available would be to do something like e.g. if (x & 0xffff0000 == 0) { // don't bother counting the top 16 bits), which is pretty much what you're talking about here. Assuming you have some knowledge of how big the number can be and how likely it is to be small/large.

sarehu
Apr 20, 2007

(call/cc call/cc)
Here's a hint: you can make an implementation for 64-bit numbers that uses the plus sign 6 times. And you can make one for 32-bit numbers that uses the plus sign 5 times.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Centripetal Horse posted:

That's a fair point, although I can't imagine going ten years of programming without having a need for, or at least a solid use case for, bitwise operations.

Hi, I'm a typical line of business application. I don't think we've met.

PT6A
Jan 5, 2006

Public school teachers are callous dictators who won't lift a finger to stop children from peeing in my plane

Munkeymon posted:

Hi, I'm a typical line of business application. I don't think we've met.

I was just writing a theme for WordPress for a client and I had to use bitmasks. I can see you not needing to use actual bit arithmetic, but knowing how to read and manipulate bits directly is still fairly necessary. To the point that you should be able to write a functional, if not optimal, bit counter in a language of your choice.

Xerophyte
Mar 17, 2008

This space intentionally left blank

sarehu posted:

Here's a hint: you can make an implementation for 64-bit numbers that uses the plus sign 6 times. And you can make one for 32-bit numbers that uses the plus sign 5 times.

To beat around the bush less, the basic idea is that if you know the popcount of the first n/2 bits and the last n/2 bits then you can just add them together to get the popcounts for all the n bits. Further, you can compute those two popcounts in parallel if n is small enough for machine integer arithmetic.

Initially, each bit of the input is its own popcount. First iteration assigns each pair of bits their popcount by adding neighboring bits together. Then each 4 bit word by adding neighboring pairs, then each 8 bit word by adding 4 bit words and so on.

For 32 bits, stolen from Sean Eron Anderson's bit twiddling hacks.
C++ code:
uint32_t v; // count bits set in this (32-bit value)
uint32_t c; // store the total here
static const uint32_t S[] = {1, 2, 4, 8, 16}; // Magic Binary Numbers
static const uint32_t B[] = {0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF, 0x0000FFFF};

c = v - ((v >> 1) & B[0]);
c = ((c >> S[1]) & B[1]) + (c & B[1]);
c = ((c >> S[2]) + c) & B[2];
c = ((c >> S[3]) + c) & B[3];
c = ((c >> S[4]) + c) & B[4];
You can technically shave it down to even fewer operations:

C++ code:
v = v - ((v>> 1) & 0x55555555);
v = (v & 0x33333333) + ((v >> 2) & 0x33333333);
c = ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; 
The basic idea isn't terribly difficult but I would not expect anyone to know or derive that on an interview. There's a simpler LUT approach which I'd think most coders could at least be prodded towards.

Xerophyte fucked around with this message at 16:50 on Jun 20, 2016

Series DD Funding
Nov 25, 2014

by exmarx

PT6A posted:

I was just writing a theme for WordPress for a client and I had to use bitmasks.

Why though

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



PT6A posted:

I was just writing a theme for WordPress for a client and I had to use bitmasks. I can see you not needing to use actual bit arithmetic, but knowing how to read and manipulate bits directly is still fairly necessary. To the point that you should be able to write a functional, if not optimal, bit counter in a language of your choice.

I guess I wasn't considering constant bitmasks because they do a decent job hiding the fact that you're fiddling bits under the hood, and I still don't because I don't think knowing that you have to or together FILE_READ and FILE_WRITE to read and write a file means you're actually familiar with bit twiddling chicanery like Xerophyte is talking about. You can copy open('file.txt', FILE_READ | FILE_WRITE) out of the help file without understanding what you're really doing there, basically.

PT6A
Jan 5, 2006

Public school teachers are callous dictators who won't lift a finger to stop children from peeing in my plane

Munkeymon posted:

I guess I wasn't considering constant bitmasks because they do a decent job hiding the fact that you're fiddling bits under the hood, and I still don't because I don't think knowing that you have to or together FILE_READ and FILE_WRITE to read and write a file means you're actually familiar with bit twiddling chicanery like Xerophyte is talking about. You can copy open('file.txt', FILE_READ | FILE_WRITE) out of the help file without understanding what you're really doing there, basically.

You don't need to write super-optimized code to make a bit counter, you just need to know how to use & to determine whether a specific bit is set. It's no more involved than using | to create a bitmask, though I suppose if you have absolutely no idea what you're doing, one is more confusing than the other.

People are getting carried away with cleverness and optimization in here, which is fine, but in an interview situation, you can just write a basic bit counter with for loops or something.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

PT6A posted:

You don't need to write super-optimized code to make a bit counter, you just need to know how to use & to determine whether a specific bit is set. It's no more involved than using | to create a bitmask, though I suppose if you have absolutely no idea what you're doing, one is more confusing than the other.

People are getting carried away with cleverness and optimization in here, which is fine, but in an interview situation, you can just write a basic bit counter with for loops or something.

std::bitset<5> foo;
foo[2] == true;

ndb
Aug 25, 2005

I had a couple of bad experiences as the interviewee, and one where I was a bad interviewee.

One time, I flew out to interview at a company, and they proceeded to test me on Ruby on Rails when I said that I don't have a lot of professional Rails experience.

Another time, I was rejected because I spent too much time trying to figure out how a boolean statement worked (I got confused with "<=" and ">=", writing them as "=>" and "=<" and then freaking out at the syntax error.) I have no defense about that one, especially since it happened just last January.

baquerd
Jul 2, 2007

by FactsAreUseless

ndb posted:

One time, I flew out to interview at a company, and they proceeded to test me on Ruby on Rails when I said that I don't have a lot of professional Rails experience.

This can actually be a pretty useful exercise. Giving a Java programmer some Ruby to figure out (with or without internet access really) shows how they deal with pressure, learning new concepts, communicating uncertainty, etc.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



PT6A posted:

You don't need to write super-optimized code to make a bit counter, you just need to know how to use & to determine whether a specific bit is set. It's no more involved than using | to create a bitmask, though I suppose if you have absolutely no idea what you're doing, one is more confusing than the other.

People are getting carried away with cleverness and optimization in here, which is fine, but in an interview situation, you can just write a basic bit counter with for loops or something.

I agree with you, assuming the candidate even remembers the operators, which they might not, because if you're making LOB CRUD apps, hitting & just once is probably an accident and you've hopefully never really used shift operators on the job. I think that makes it a bad question for screening people for a job making LOB CRUD stacks, but that's just me.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.
I think the worst interview I attended was for a medical technology company. Their CEO went on this huge tangent about how they were very focused on technology/programming. Immediately after that their CTO asked what you could do with classes in c++ that you couldn't do with structs.

I said they were identical except default public/private, he told me I was wrong, then I pulled out the relevant section of the specification (which I keep on my iPad), and told him he was probably thinking of POD types, but that classes could also be POD types, and nothing stopped a struct from not being a POD.


I also had a few phone calls with games companies over typical algorithm stuff. One I provided an amortized O(1) solution with worst case O(N) and then I had to spend 10 minutes explaining amortization to the interviewer. Another couldn't grok an expanding/collapsing window to find some array element in O(N) using two iterators. Another got super confused when I provided a solution in big-theta(NlogN).


Hopefully I'm done dealing with terrible interviewers for a long while though. :unsmith:

PT6A
Jan 5, 2006

Public school teachers are callous dictators who won't lift a finger to stop children from peeing in my plane

Munkeymon posted:

I agree with you, assuming the candidate even remembers the operators, which they might not, because if you're making LOB CRUD apps, hitting & just once is probably an accident and you've hopefully never really used shift operators on the job. I think that makes it a bad question for screening people for a job making LOB CRUD stacks, but that's just me.

If so, I wouldn't fault them for an incomplete answer if they admitted they couldn't remember the bitwise AND operator or something. It is enough to know that such a thing exists and it would be the right tool for the job. If they constructed something out of modulus operators and division by 2 I'd be less thrilled but I'd still accept it.

You could equally argue that most people don't need to know how to implement a linked list structure since it's provided in nearly every language at this point, but it's still something I'd expect a developer candidate to be able to do.

Centripetal Horse
Nov 22, 2009

Fuck money, get GBS

This could have bought you a half a tank of gas, lmfao -
Love, gromdul

Xerophyte posted:

For 32 bits, stolen from Sean Eron Anderson's bit twiddling hacks.
C++ code:
...

c = v - ((v >> 1) & B[0]);
c = ((c >> S[1]) & B[1]) + (c & B[1]);
c = ((c >> S[2]) + c) & B[2];
c = ((c >> S[3]) + c) & B[3];
c = ((c >> S[4]) + c) & B[4];

...
The basic idea isn't terribly difficult but I would not expect anyone to know or derive that on an interview. There's a simpler LUT approach which I'd think most coders could at least be prodded towards.

This is the sort of thing I had in mind when I talked about reducing or eliminating the loop. In fact, I used something very similar for manipulating pixel data when I was writing my implementation of Roger Alsing's EvoLisa.


PT6A posted:

You could equally argue that most people don't need to know how to implement a linked list structure since it's provided in nearly every language at this point, but it's still something I'd expect a developer candidate to be able to do.

This is exactly why I want a thread where interviewers post the challenges they present to candidates. I think it would be fun to do this, and see how other goon developers solve the same problem.

Adbot
ADBOT LOVES YOU

genki
Nov 12, 2003

leper khan posted:

I think the worst interview I attended was for a medical technology company. Their CEO went on this huge tangent about how they were very focused on technology/programming. Immediately after that their CTO asked what you could do with classes in c++ that you couldn't do with structs.

I said they were identical except default public/private, he told me I was wrong, then I pulled out the relevant section of the specification (which I keep on my iPad), and told him he was probably thinking of POD types, but that classes could also be POD types, and nothing stopped a struct from not being a POD.


I also had a few phone calls with games companies over typical algorithm stuff. One I provided an amortized O(1) solution with worst case O(N) and then I had to spend 10 minutes explaining amortization to the interviewer. Another couldn't grok an expanding/collapsing window to find some array element in O(N) using two iterators. Another got super confused when I provided a solution in big-theta(NlogN).


Hopefully I'm done dealing with terrible interviewers for a long while though. :unsmith:
To be fair to those interviewers, one of the major indicators for success within a company is attitude, and having someone that looks down on their peers because their peers may not be as knowledgeable as them is probably someone you don't want to hire into your team. It isn't clear from your statement that that's something that you did (I would make that assumption from saying "terrible interviewers" but maybe that was just a humor comment and not an condemnation of their ability to do their jobs), just something that it's important to note if someone ever gets rejected from an interview where they actually knew more than the interviewer (at least, so far as you know, making interviewees explain basic concepts really helps expose what it will be like to work with that person in a lot of ways, so it's a useful interview technique).

Of course, if the interviewers were simply not prepared to deal with the answers to their question, then yeah, that's on them... (though sharing knowledge of a new and different technique can be friendly and englightening for the interviewer and be a potential nice anecdote in the feedback!)

  • Locked thread