% python -mtimeit -s 'x=1' 'x<<3'
10000000 loops, best of 3: 0.061 usec per loop
% python -mtimeit -s 'x=1' 'x*8'
10000000 loops, best of 3: 0.0602 usec per loop
% pypy -mtimeit -s 'x=1' 'x<<3'
1000000000 loops, best of 3: 0.00103 usec per loop
% pypy -mtimeit -s 'x=1' 'x*8'
1000000000 loops, best of 3: 0.00103 usec per loopSome interviewers (not just the "homework") raise their bar by not allowing you to make any tiny mistake. And I just don't get it. If someone is good enough to write something like a lite version of Hacker New website in hours, I'm not going to turn him/her down because of such mistake.
I did interviews at a company for about 2 years and there was constant pressure from management to do trivial crap like that, it finally came to a head and I invited management and one of the "rockstars" to do a mock interview.
When it was evident that the person they thought of as a "rockstar" could not solve these tests(without prior knowledge of the problems), they immediately discounted them as a worthless and stopped bugging me (about that, of course not about everything else).
If I found bit shifting in an interview code sample as a replacement for basic multiplication, I would ask the developer why they chose to do it that way. They'll either a) calmly explain that their computer science classes taught it that way or it's a habit they've adopted after writing code for embedded systems or similar where the optimization actually made a difference, or b) their ego will make an appearance with a "because I'm so senior" attitude. The latter is not a good sign.
My company does 4 hour work-product tests, and we pay each of the candidates for their time. We're in Portland, not SV, so maybe there is a difference in environment.
It shows a level of thought about people that goes beyond ping-pong tables and free pizza and coke (and ironically probably costs less than those things).
Let me guess ... you are happy working there right?
static const int eight = 8;
x * eight;
Sometimes magic numbers are just that - numbers. Adding constant definitions is often a good thing, but sometimes just adds noise. static const int days_per_week = 8;
:-).