But if you take a second and think about it, how the hell could these same people who fail fizzbuzz write production code in previous companies? Are you really saying that you believe that fizzbuzz is more complicated/difficult than their previous work?
As someone who's run lab experiments and who's seen a bunch of surprising results, trust me when I say that shocking results usually mean that you're running a test that you don't understand.
In this case, you're probably testing for a host of things that have nothing to do with day-to-day engineer performance.
Maybe they had a lot of supervision, or were someone that could talk a good game to management but didn't deliver, or maybe they just fiddled around with minor stuff in other folks' code.
While experience is obviously a really good thing and a useful thing, if they can't write fizzbuzz you'd have to re-evaluate that experience in the light of new knowledge.
What I'm pointing out is a fundamental problem with coding problems.
FizzBuzz is a relatively simple problem to solve, so if fizzbuzz fails as a test for coding ability, then it's fairly likely that all coding problems fail.
There's are probably better metrics (faster, more uniform, etc) that you could use to figure out how good a coder is.
For example, one thing I've noticed is that I'm fairly aware of the skill levels of everyone I've ever worked with. I think it might be interesting to see how peers rate each other (A players can tell A players, and so on)- maybe that would be the metric that's most useful. All I know is that FizzBuzz probably isn't it.
One last thing I need to add: the people who are dramatically more productive coders are not always dramatically more productive because they code faster or better. It's often because they enact/enable processes that amplify the other developers. (e.g. the developer who pushes the company to have a hackathon, or the dev who creates machine images preconfigured for deploying test and dev builds).
No no, not the average engineer, the average applicant. Huge difference.
I have to admit that I myself rarely need to use it. When I first read about FizzBuzz I tried to solve it by division and then comparing the floating point result to a rounded int result (i.e. circular way to get the remainder).
I'd be interested to see how many people pass if you simply remove the remainder operator part of it entirely. My guess is that near 100%.
FizzBuzz is still less "unfair" than a lot of the trick programming questions, riddles, or random CompSci trivia that many companies (Google, Microsoft, etc) do.
This is one of the reasons I would never even apply at a Google. I don't perform well programming wise under that level of pressure and my "random trivia" reserves are low.
I'm sympathetic to complaints about overly technical interviews (I've bombed a few in my day because of stress and/or ignorance), but as others have pointed out, this is FizzBuzz. I'm generally very bad at interview/algorithm puzzles, but I could even figure this one out pretty quickly.
The big difference between the two metaphors is that mine has direct impact on your personal life and negative consequences are gonna be seen as your fault, while yours is a company threat - fixing it will get you seen as a hero, not a disgraced villain.
Unless they "cheat" this should give you a good idea of what they're capable of. The cheating should also show up if they cannot explain it or why they wrote it the way they did.
Additionally, they could spend some time with the team they'd be working in, pairing (or whatever) with other members and really demonstrating their abilities.
It's not really that difficult to get away from the whole "technical question at the interview" problem, and I'd wager that in the long-term it'd be better for all concerned.
Even Google lets you try again in a year.
if !multiple_of_3(i) && !multiple_of_5(i)
output = i
edit: In order to avoid overwriting output, the solution should read... if !multiple_of_3(i) && !multiple_of_5(i)
output << iIf you get "close enough" on paper and pencil under the pressure of an interview, that's great. You can walk through debugging it if you want to see more, but I wouldn't hold even basic logic errors against someone.
I certainly admit that when coding on my own I usually get all kinds of stuff wrong that I fix as I write tests and iterate.
The results were quite frankly a disaster, no better than what Joey found (though I didn't do enough interviews for a statistical sample).
Unfortunately my limited observations have lead me to believe that too many developers (particularly in the enterprise environments) are used to working on legacy codebases that they hack and change until the bug they are fixing goes away. Many rarely implement features much, if at all, and the ones they do are heavily broken.
To my surprise, the candidates' solutions were either bang-on or way off. The guy who asked "Do you think I should use a loop?" had to be cut off at the ten-minute mark, and his paper had only the start of a C-syntax for loop and a lot fo scratched-out lines.
Admittedly, having a variable that contains either an integer or a string is atrocious programming style, but some people do actually like languages that allow that, so it is par for the course in the given situation.
No. Though output << i.to_s will produce the same result, his code is correct. And yours isn't if you do output << i
1. If not a multiple of 3 or 5 or 15, output = i.
2. If a multiple of 3, output << fizz.
3. If a multiple of 5, output << buzz
4. If a multiple of 15, "fizzbuzz". Already covered in 2 and 3 owing to <<
Apparently people mess up fizzbuzz even when they know it:)
In each loop, he initializes the output variable to an empty string. If the current integer is not a multiple, he replaces the empty string with the integer. If it is a multiple, he doesn't know which one it is, or if it's a multiple of both, so he appends the text to the existing string variable. At the end of the loop, the string is output.
Since the `output = i` line is the only assignment that occurs when that condition (not a multiple of either) is met, it makes sense to just reassign the variable rather than append to it. It might be less flexible, sure, but flexibility isn't required here.
"" << 0x41 # => "A"If the number is not multiple of 3 or 5, you must output the number. That's what is he doing.
He prints output at the end of each iteration, setting it to empty string at the beginning.
Be careful with this kind of test evaluation:
1. The problem isn't new to you - you have already had the problem in your head for days or even years. Whether you admit it or not, you already have a good idea of how to approach the problem.
2. You are not under stress, as the candidate would be.