I was incredulous when I read this observation from Reginald Braithwaite:
Like me, the author is having trouble with the fact that 199 out of 200 applicants for every programming job can't write code at all. I repeat: they can't write any code whatsoever.
The author he's referring to is Imran, who is evidently turning away lots of programmers who can't write a simple program:
After a fair bit of trial and error I've discovered that people who struggle to code don't just struggle on big problems, or even smallish problems (i.e. write a implementation of a linked list). They struggle with tiny problems.So I set out to develop questions that can identify this kind of developer and came up with a class of questions I call "FizzBuzz Questions" named after a game children often play (or are made to play) in schools in the UK. An example of a Fizz-Buzz question is the following:
Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".Most good programmers should be able to write out on paper a program which does this in a under a couple of minutes. Want to know something scary? The majority of comp sci graduates can't. I've also seen self-proclaimed senior programmers take more than 10-15 minutes to write a solution.
Dan Kegel had a similar experience hiring entry-level programmers:
A surprisingly large fraction of applicants, even those with masters' degrees and PhDs in computer science, fail during interviews when asked to carry out basic programming tasks. For example, I've personally interviewed graduates who can't answer "Write a loop that counts from 1 to 10" or "What's the number after F in hexadecimal?" Less trivially, I've interviewed many candidates who can't use recursion to solve a real problem. These are basic skills; anyone who lacks them probably hasn't done much programming.Speaking on behalf of software engineers who have to interview prospective new hires, I can safely say that we're tired of talking to candidates who can't program their way out of a paper bag. If you can successfully write a loop that goes from 1 to 10 in every language on your resume, can do simple arithmetic without a calculator, and can use recursion to solve a real problem, you're already ahead of the pack!
Between Reginald, Dan, and Imran, I'm starting to get a little worried. I'm more than willing to cut freshly minted software developers slack at the beginning of their career. Everybody has to start somewhere. But I am disturbed and appalled that any so-called programmer would apply for a job without being able to write the simplest of programs. That's a slap in the face to anyone who writes software for a living.
The vast divide between those who can program and those who cannot program is well known. I assumed anyone applying for a job as a programmer had already crossed this chasm. Apparently this is not a reasonable assumption to make. Apparently, FizzBuzz style screening is required to keep interviewers from wasting their time interviewing programmers who can't program.
Lest you think the FizzBuzz test is too easy-- and it is blindingly, intentionally easy-- a commenter to Imran's post notes its efficacy:
I'd hate interviewers to dismiss [the FizzBuzz] test as being too easy - in my experience it is genuinely astonishing how many candidates are incapable of the simplest programming tasks.
Maybe it's foolish to begin interviewing a programmer without looking at their code first. At Vertigo, we require a code sample before we even proceed to the phone interview stage. And our on-site interview includes a small coding exercise. Nothing difficult, mind you, just a basic exercise to go through the motions of building a small application in an hour or so. Although there have been one or two notable flame-outs, for the most part, this strategy has worked well for us. It lets us focus on actual software engineering in the interview without resorting to tedious puzzle questions.
It's a shame you have to do so much pre-screening to have the luxury of interviewing programmers who can actually program. It'd be funny if it wasn't so damn depressing. I'm no fan of certification, but it does make me wonder if Steve McConnell was on to something with all his talk of creating a true profession of software engineering.
Due to high volume, comments for this entry are now closed.
I've become infected with the FizzBuzz fever, too.
main = putStr . unlines .
foldr (zipWith ($)) (map show [1..100]) $
[replace "FizzBuzz" 15, replace "Buzz" 5, replace "Fizz" 3]
replace s n = fix ((replicate (n-1) id ++ [const s]) ++)
Console.Writeline("1");
Console.Writeline("2");
Console.Writeline("Fizz");
Console.Writeline("4");
Console.Writeline("Buzz");
Console.Writeline("Fizz");
Console.Writeline("7");
Console.Writeline("8");
.
.
.
Yeah it's not elegant (on purpose). But it shows that I can follow the directions and produce code that works. If the interviewer wants to do a code review and ask me to defend my methodology, I'm happy to do so.
Can anyone post the answer to the vowel/even number logic puzzle. I hate logic puzzles, but the programmer/pessimist in me says all 4 because you never know what the next input would be. However, I'm guessing the answer he wants is "A" and "2"?
Mike H on February 27, 2007 7:00 AMto LKM:
i am sorry if you felt my message as hostile. english is not my native language and i may sometimes seem a bit rude (i do seem rude anyway on my daily life). it was not meant to be offensive at all, and i deeply apologize if you took it that way.
anyway:
"Do you understand that by using a local stack instead of the call stack, the computer needs to keep track of much less information and needs to do much less work building and tearing down the call stack? In most languages, using a stack instead of recursion speeds up your app tremendously."
yes i do understand. it is just less error prone to let the computer do the stack keeping for you. also, a good compiler will have a good optimizer which will make handcrafted optimization look slow (unfortunately, apart from tail recursion, recursion is not the favorite playground of optimizers).
but, as always, the solution used to solve the problem will depend greatly on the domain you are coding for. you will not code the same algorithm for an embedded system, a large-scale data-center or a desktop application. you will definitely have to make tradeoffs between resource usage, reliability, and ease of programming.
rien on February 27, 2007 7:01 AMPerhaps I'm failing my Sense Motive roll, but I'm truly saddened by the number of people who not only posted the solution, but posted the *wrong* solution.
Go back and count the "solutions" that failed to print the values from 1 to 100. Go back and count the solutions that started a loop at zero instead of one.
So sad. I really hope that they were deliberately wrong to keep the script kiddies from getting a job. In fact, my sanity requires that I chose to believe that.
Randolpho on February 27, 2007 7:04 AMint main() {
printf("Get back to work!\n");
return 0;
}
rien: I guess something was lost in translation then :-)
Sure, creating your own stack has its own sets of problems, and it's not suitable to replace all usages of recursion. It's often a good idea, though. I'd say that using a stack instead of recursion is not so much "handcrafted optimization" as it is "avoiding expensive patterns where they are not needed" :-)
LKM on February 27, 2007 7:09 AMFortunately, coding is merely my hobby. The one time I applied for a job, I did have to do some basic code in front of the owner of the company. He asked me to do something basic that I hadn't done in C in many years, so I couldn't remember the commands, so I had to resort to the last language in which I had actually done it: REALbasic. That was a bit embarrassing, to say the least. I also had to recode the script in front of him, because I wrote it under a minute and had a few logical errors in it, which I corrected. Then I optimized it in front of him, which I couldn't walk away without doing. I didn't get the job (thankfully), but I was one of the top two candidates. The only thing that won out the other guy in the end was that he had more experience with .NET than I did. Or so they told me. Could very well have been that I was a colossal embarrassment, but they were too kind to tell me. Who knows? But I do know that I'm glad I didn't get the job. I just haven't got the chops to sit in a room and code all day, not even for pay.
Jae on February 27, 2007 7:09 AMSo, exactly where are you FINDING these job candidates? sounds like a piss poor advertising and recruiting practice if 99.5% are not valid candidates.
Geesh, I advertise on Craigslist in Austin or Phoenix and over 1/2 of the people who apply are able to pass a test like this. And this is with modest pay for an easy and flexible work at home job (ssh, svn, etc). Plus I get maybe 10 to 15 replies running the advertising 1 time, and those replies come in within the first 5 days. So I get 5 to 8 real job candidates and I can focus on long-term aspects of which person is best.
In other words, just like writing a good resume is important, writing a good job description and knowing where to find people is just as important.
Stephen Gutknecht on February 27, 2007 7:10 AMFor some reason,(maybe because I am now only a hobbiest) I still use qbasic for brainstorming and pseudo-code)
X=0
Do
X = X + 1
outstring$ = ""
If x mod 3 = 0 then outstring$ = "Fizz"
if x mod 5 = 0 then outstring$ = outstring$ + "Bizz"
if len(outstring$) = 0 then outstring$ = str$(x(
print outstring$
Loop Until X = 100
Here's a "clear" Lisp version:
(defun fizz-buzz ()
(loop for i from 1 to 100
do (cond
((= 0 (mod i 3) (mod i 5)) (format t "FizzBuzz~%"))
((= 0 (mod i 5)) (format t "Buzz~%"))
((= 0 (mod i 3)) (format t "Fizz~%"))
(t (format t "~a~%" i)))))
lua still nice even doing what the problem states!
for i=1,100 do
fizz= (i%3==0) and "Fizz" or ""
buzz= (i%5==0) and "Buzz" or ""
number= not ((fizz=="") and (buzz=="")) and "" or i
print(number..fizz..buzz)
end
"It is interesting that at least two solutions given in the comments are wrong. People don't even know that they can't program."
People might know how to program, they just don't test what they program!
Jos Rui Abreu Mira on February 27, 2007 7:13 AMIf I'd been given the "swap 2 values with no temp variable" problem before yesterday, I probably would have said "you can't do it".
Now that I've seen the trick (which isn't a general solution. It only works for integers, and only those containing values that won't overflow when added), I probably would have said "you shouldn't".
I've been developing software professionally for 18 years now, for fun about 9 years before that, and have at least 6 assorted Free or Public Domain projects under my belt. Does my "incorrect" answer to that question make me a bad programmer in your eyes? Given that your "correct" answer is something I'd slap someone for trying in any code I have to maintain, I think I'd prefer to not get that job anyway.
As for the issue about recursion, in my experience most software developers (even fairly good ones) are scared of it. I wouldn't consider that a deal-killer for hiring. I was scared of it too, until I took a Lisp course in college. Its probably a better test of Lisp exposure than anything else.
On the other hand, if you are scared of it, be honest enough to admit it. Don't throw me some (possibly true) pablum about explicitly using a stack being just as good, and faster in some cases.
If an algorithm is naturally recursive, recursion is probably the best expression of that. As for the speed issue, I agree that a good programmer doesn't do things that are going to be massively slow. However, they also don't pervert their source code for optimization purposes. That's the compiler's job. If the compiler fails, *and* you have a known speed problem, *and* you have tracked a big bottleneck down to that chunk of code, then you may source-level optimize. Otherwise, just make it as understandable as you can, please.
However, I would consider "I have trouble with recursion, and so does nearly every other developer who will have to maintain this code", a compelling argument.
T.E.D. on February 27, 2007 7:15 AMI interviewed at a place with a fairly stringent testing regime last year. There were many "write on the board" SQL questions and some Java pair programming with one of the team leaders.
Unfortunately, although I nailed the whiteboard part, I did poorly on the pair programming portion. I didn't handle the context shift between VB (which I was using on the current gig) and Java well enough, and kept foolishly expecting Eclipse to get the case on my variables correct for me, leaving off semicolons, stuff like that. It was embarrassing, considering that six to eight months previously I had been doing a lot of Java.
I suppose I would have done better had I freshened my Java knowledge a little before the interview, but I had an informal offer on the table for a lot more money and was going through with this interview for, shall we say, domestic political reasons (i.e. my wife didn't think the existing offer was official enough and would have killed me if I'd cancelled this interview. Because of the pay discrepancy and the awkwardness that would have ensued in trying to negotiate an informal offer against an inferior, but formal one, I actually dreaded the prospect of an offer.)
Highly Paid Consultant on February 27, 2007 7:15 AMSome of these tests are fine, but I'm sorry... OCTAL? Almost -nobody- uses octal anymore. You're rewarding programmers for learning stuff they'll never have to use. If they ever need it for some crazy reason, they can always use google and spend two minutes learning how to interpret it.
These tests can't determine whether a programmer is economical, which is the secret to what actually makes programmers good. I've seen many programmers who are much smarter than I am destroy projects, because they spent too much time hacking on the 20/80 stuff instead of picking their programming battles wisely. Good programmers get the job done, which is why the best test for programmers should be their ability to create stuff (like projects, OSS and whatnot).
(python)
for i in range(1,100):
if i % 15 == 0: print(str(i) + ' fizzbuzz')
elif i % 5 == 0: print(str(i) + ' buzz')
elif i % 3 == 0: print(str(i) + ' fizz')
(c#)
for (int i=1; i=100; i++)
{
if(i % 15==0) Console.WriteLine(string.Concat(i, " FizzBuzz"));
else if(i % 5 == 0) Console.WriteLine(string.Concat(i, " Buzz"));
else if(i %3 == 0) Console.WriteLine(string.Concat(i, " Fizz"));
}
I had recently gone through a few interviews - some good and some bad.
I thoroughly enjoyed one in particular for Blackbaud (Charleston, SC) where the team lead asked me through some real basic questions (something like storing people's favorite activities) that covered relational database, OO, and web-based design concepts. Nothing particular hard - but worthy of actual thinking. Then she went and expanded the basics a few times and had me explain what I would do - which covered nicely aspects of software maintenance that I reasonably expect most get to deal with. I did get the offer, but couldn't take it (in the end) because I had hoped I would sell a house in another state ... it was very complicated :)
Then I think back to another interview where there was a programming test. And I just completely bombed it ... I mean TOTAL brain fart. How embarrassing! I've gone through others and did completely well, but like how some interviews go (or at least for me), some go really well, and some just don't. Including programming tests. Well, the job was probably too far west (San Francisco) for my family anyway...
Chris Harmon on February 27, 2007 7:20 AMWe've had a fair number of interviewees who couldn't write a very simple program. But I bet a fair number got home and realized that they could do the task easily under normal conditions, but had freaked out with interview anxiety.
Andrew Webb on February 27, 2007 7:21 AMseq 1 100 | sed '0~3 s/[[:digit:]]*$/Fizz/
0~5 s/[[:digit:]]*$/Buzz/'
While I understand the problem of programmers who can not program I really have no empathy for those of you doing the hiring.
I went to a little community college and got an A.A. while there I learned to program in C/C++, pascal, cobol, QB, and AS400. Since college I have taught myself 3 new languages and if I were to interview for a programming job would have brushed up on the syntax enough to have easily passed any of the "tests" listed on this page, yet none of you would have let me get that far.
Since I have only an A.A. no one seems to want to even bother interviewing me much less test me to see if I "have the skills". Yet they fall all over each other trying to "catch" one of the kids that used to come to me for help on their assignments week after week. Because those same kids went on to get a B.A. or a B.S. while I decided I was deep enough in debt and went out into the world to do basic comp. repairs.
It has been my experience that those who programmers who fail your little tests are most likely failing not because they can't program but because they have a problem applying their knowledge (it is a fine line but a valid one). Much like most high school grads these days seem to know the basics of proper grammar but could not compose a decent letter to save their lives.
That's my opinion anyway, take it for what it is worth.
quote: it's the standard a=a+b, b=a-b, a=a-b problem
Hopefully a and b aren't near MAX_INTEGER. In fact this is a worse solution than doing something obviously wrong as it will only come up in the weird cases making it even harder to debug. This is a terrible way of doing it, you fail!
BlogReader on February 27, 2007 7:27 AMToepopper wrote
Very very common, alas. I once interviewed a candidate for a VBA job (yes, you can stop booing for the peanut gallery) whom I asked to swap two variable contents without using a temp variable. It's the standard a=a+b, b=a-b, a=a-b problem. His answer? Well, I can't do it in VBA, but if you let me use Excel I can put the values in two cells and swap the cells' contents using a third cell.
We hired the guy who said, well, "if they're integers, then I'd do it by a=a|b, b=a^b, a=a^b. But I don't know how to do it if they're strings."
Toepopper on February 27, 2007 01:49 AM
I think Toepopper hired the wrong fellow, because his "swap program"
is logically flawed. After looking up the meaning of the | ^ operators (i.e. | = bitwise OR and ^ = bitwise XOR), I attempted a formal proof. I could not get it to work out. So I tried a simple case. Suppose we have 1-bit words and
a = 1
b = 1
After a = a|b:
a = 1
After b = a^b
b = 0
After a = a^b
a = 1
And you can see, a swap has not occurred.
R. Butler on February 27, 2007 7:29 AMHi!
I am writing from India.India is becoming famous with IT and lot of software development stuff happening here.
But,to my surprise,people in large organizations hires the candidates from the campuses with bulk entity and not even asking any fizz buzz questions.
I have given number of test with smaller organizations which requires to pass technical test or code right away at the time of test.
and I opted for such a company.Now,reading this article I think my decision is *really* good.
Another point to be made is should *years of experience* really teaches us these things in programming???
and if no then why do all software companies ad mentions the years of experience instead of asking for some other point...
please comment..
Lalit on February 27, 2007 7:34 AMIt seems to me that most of the comments here are focused on the actual code solution for the FizzBuzz question. I would like to step back and talk about the actual lack of programming knowledge possessed by those that apply for these programming jobs. I would say that the reason that so many numbskulls apply for these jobs is because somewhere in the job requirements it says that applicants must have at least a Bachelors in computer science. Most of the best programmers I have ever known, including myself, do not have a degree of any kind, and in my case, never went to college. Yet, many companies will simply push your resume aside if they see that you do not have the required degree, no matter what you skill level may be. A degree is just a piece of paper that says that you have sat in a class for x number of hours learning about something that you may or may not remember when you leave. If companies want to find real programmers with real programming experience they need to broaden their search or have a little slack when it comes to their job requirements. I guarantee that they will interview many more applicants with a deeper knowledge of the force.
Anthony Decena on February 27, 2007 7:35 AMDave: "Note that the FizzBuzz Test requires at least some simple number theory thinking."
It's extremely simple number theory thinking, that people in all fields should know. The word "multiple" is basic vocabulary, and any grown-up with an IQ over 80 ought to be able to understand what it means.
Ben Atkin on February 27, 2007 7:38 AMThat's a relief. I'm like "Dang! What if I'm one of the ones who can't do that?!" The script below is probably a little inelegant, but it works. Took about 5 minutes, but part of that was talking to a co-worker about nasal irrigation.
?php
for($i=1; $i=100; $i++) {
if ($i%3 == 0) echo "Fizz";
if ($i%5 == 0) echo "Buzz";
if ($i%3!=0 $i%5!=0)
echo $i;
echo "br\n";
}
?
Or how about,
$s = '';
for($i=1; $i=100; $i++) {
$s .= ($i%3==0)?"Fizz":"";
$s .= ($i%5==0)?"Buzz":"";
$s .= ($i%3!=0 $i%5!=0)?"$i":"";
$s .= "br\n";
}
echo $s;
?
I prefer readability to compactness.
Mike H, the answer to the vowel/even problem is "A" and "3". It would be all four only if my theory were if-and-only-if, but that's not what I specified.
Jeff, thanks for posting this one, I've found replies really engrossing. Readers identified three problems worth solving:
1. Write FizzBuzz code
2. Distinguish good programmers from lousy ones in an interview
3. Fix the educational system that produces these morans
It's been a pleasure to read proposed answers for all.
John Pirie on February 27, 2007 7:42 AMBig Playa - re-read the requirements... you failed.
I ask the candidate to write a simple but full-fledge class from scratch. (Many can't)
I also provide a series of assertions and ask the candidate to write code that passes those tests.
However, writing code on a whiteboard is hard even for me, and I've written a lot of code in the last 20 years. These days I'd provide the candidate with a laptop (if they don't have one with them) and watch them code and test their code.
Charles Kens on February 27, 2007 7:45 AMAnthony - thats what i look for when hiring - experience and aptitude over qualifications. and i really dont care how many "certified whatever" post-college qualifications you have either.
a portfolio is essential. past experience too and a willingness to learn. some of the best coders i've met have never gone to college either. the ones that did go to college and were good coders after , were coders in their teens pre-college.
i think the problem lies with folks that never programmed before college and just did the course to get this mythical enormous "I.T. salary", without necessarily having any aptitude or love for the subject.
I dont know a lot of the languages used in here, but im guessin about one fourth of the answers to FizzBuzz are wrong.. I mean:
for num in range(1, 101):
if not num % 3:
print "bizz"
elif not num % 5:
print "buzz"
else:
print num
I dont know Python but that code looks like it doesnt print the bizzbuzz, am I rigth or is Python just weird?
i hope Im wrong cause this is sad..
I can't believe no one has put up the Perl Obfuscated version of the FizzBuzz:
map{$_=(!($_%3)!($_%5)?"caddeidd":(!($_%3)?"cadd":(!($_%5)?"eidd":$_)));y/cadei/fizbu/;print"$_\n"}(1..100)
My obfuscation powers are weak this morning, I'm sure it could have been done much better.
Incidentally, if this were the interviewee's answer, I would probably not hire him. I might invite him to become a member of Perl Mongers, though (http://www.pm.org)
TimothyChenAllen on February 27, 2007 7:51 AMAbout 8 years ago, after a UK conference on teaching the new language of Java, one of the attendees said that we certainly needed to change something -- the final year students on the Comp Sci course at his prestigious university were not confident in writing any program, even one just 10 lines long. Other people there agreed that it was not much better, if any, where they worked. Surprised, I went back to my much less prestigious place where all our students took joint degrees, Computing and Maths, Computing and History etc and and checked with my final year OO class. I had real difficulty explaining the question, even though I upped the size to 20 lines -- they just could not imagine anyone on our (half a) degree course, even those who had dropped programming at the earliest opportunity, being unable to write proper programs. What was the difference? Maybe a culture of 100% attendance, and the fact that, not being much of a research establishment, we did not farm out the practical labs to uninterested grad students.
On recursion, I stand by my advice to students. You should know what it is, how it works, and how to program it. But you should _never_ use it in production code, because whoever maintains it may not grasp what is going on.
On swapping the values of two variable without involving a third, I am torn. I agree it is irrelevant to much of modern programming, and is probably not taught in most places. But it does provide a good test to see if someone has read around the subject a bit -- and if they haven't heard of it you could use it like Ben's test to see if their eyes light up when you say it is possible.
Mike Woodhouse - "As I'm about to start looking for a programmer I shall be able to implement my long-cherished plan of asking candidates to submit a page or so of what they consider to be "good code"."
So where can we send our resumes/good code?
And yes, I can write the fizzbuzz thing. :P
Telos on February 27, 2007 7:54 AMI must say, that things like this are necessary. I hired developers for a small low budget startup before and you get any hack who has written HTML applying as a "programmer".
Also, knowledge of the framework is beneficial but does not mean you can write a line of useful code. It means you know how the framework works, and frankly that's what docs are for.
A true "programmer" can write code without knowing the framework and generally the code will run efficiently and well with only minimal need for tweaking to optimize it for the framework it's on.
What is recursion and hexydecimal?
.
.
.
.
.
Sorry, couldn't resist.
all right. At least let's make it interesting.
Post the *tests* for FizzBuzz that you'd write *before* writing code !
Heck, I'll take unit and/or acceptance tests.
What's pretty dang funny is how many of the code examples above are wrong. That shows either one of two things, you misunderstood the requirements, or the even more fatal, YOU DIDN'T TEST YOUR CODE. Also the amount of of bombs we drop on suicidal muslim extremists has no bearing on this topic. As for outsourcing my old boss, when told we needed two more guys for a certain project, would say "OK get me 10 indians".
zetaprime on February 27, 2007 8:02 AMuglydawg: I don't even think a BS is enough these days. Completely unable to find a good programming job with mine. I was lucky enough to get a clerical position at my current company, and then the main programmer for my department left so I stepped in.
The problem is I'm still technically in the clerical position because they won't promote me. :(
Telos on February 27, 2007 8:05 AMThe point of the interview should not be just to find a question that will trip people up. I'd get the swapping variables question wrong (well not any more) but I've generally do better the more technical the interview. It would seem silly to give the FizzBuz test and say "HA! You got the syntax of the modulo operator wrong (while writing the program out longhand under the pressure of an interview and not having tools to unit test it)! You are NOT a programmer!" It's the people like that the database analyst I interviewed who couldn't write a SELECT statement that deserve that ridicule. (Then again you might be looking for an embedded systems engineer who can do the variable swapping thing and not care if they know SQL. It's not one-size-fits-all.)
Marc on February 27, 2007 8:09 AMCan anyone post the answer to the vowel/even number logic puzzle
I hate these puzzles as well, but because they often hinge on some pedantic phrasing. In "the real world", there is usually some system against when you can test your understanding normally, some shared organizational expectation of the meaning, or some person involved in writing the spec/question you can go to for clarification. (that is, unless you're trying to maliciously follow the spec =-) )
Now I'm not actually familiar with this puzzle, but the phrasing makes the answer pretty clear in my head.
"I have a theory that if there is a vowel on one side of a card, then there will be an even number on the other side"
That is, he says "vowel on one side = even number on other". He's not saying that whenever there's an even number there will be a vowel. He's also not saying that a consonant implies odd number (similar to previous sentence).
You only need to check one card: "B"
Chris on February 27, 2007 8:10 AMI read statements like "demand for programmers is outweighing supply" and "99% of comp sci grads cant write fizzbuzz" and its very encouraging. I didn't go to school for comp sci, but I could write the fizzbuzz in under ten minutes, including the time it took me to figure out how to use g++ from the command line. I'm by no means an excellent programmer, but if most applicants are really that bad, then I think I could be quite competitive. Is that a bad attitude? I'd like to think not, because unlike many people who would apply for these jobs, I have a desire to learn more than what's required to stay employed.
What do you think? Should I not even bother if I'm not already an incredible programmer? Would I just muck up a solid team, or is common practice to "level up" on the job?
Unlike most comp sci grads, I'd be in it for the fun of problem solving, with salary in second place.
blkmage on February 27, 2007 8:15 AMI have to agree with the premise of the article. Most programmers really can't program.
We give a very simple programming test that basically asks applicants to sort a list of names by first and last name. It is pretty trivial. Most applicants either totally botch it or end up giving up after four hours or so. Seriously, it has been the best litmus test we could possibly have hoped for.
Matt on February 27, 2007 8:18 AM
I saw some comments criticizing the poster for providing the answer to the question.
The difference between skills assessment and sadism is that when you are assessing skills you tell the applicant the answer you were looking for. It's supposed to be a learning process for both sides.
Not sharing the answer is intellectual bullying and having been on both sides of the interview table it would make me very leery about a firm that won't answer its own questions.
calenti on February 27, 2007 8:19 AMAt my company we use a considerably more complex programming test, but we only hire "senior" level type programmers, and our job postings specifically state we are looking for senior programmers.
For the java programmers, for example, we require them to write a webpage that will get data from a database, display it, let the user edit it, and save it.
For C programmers it's an exercise in reading and parsing a data file and generating a report of its contents.
These tests also require knowledge a few non-programming things that are pretty basic to the unix programmer (and we include unix in the job postings, so we expect them to know the basics), like telnet and ftp.
Almost all the candidates who take the test literally don't know how to begin. We've had computer science graduates who don't know unix (when I was in college we ONLY used unix, and I'm not *that* old - I never had to do punch cards), who don't understand what IP address is, don't know how to ftp. We rarely get anybody who even makes it so far as to be able to begin writing code. Of the few who make it that far, very few of those manage to write anything worthy of consideration. It takes a looooong time to find acceptable candidates. I suppose senior programmers are less likely to be looking, and when they do they probably use their network more than job boards, but even so, it's pretty depressing. Or entertaining, depending on your outlook...
It's one thing for a person with limited experience, but who has written functioning code, to apply for a senior programmer position, but to not have one single skill requested in the job posting? For a SENIOR position?! I'd like to know what the hell these people are thinking! And we tell them before they come in that there's going to be a technical test, so it's not like it's a surprise when they show up. And even though they know they don't have any of the technical skills being sought, they still show up and waste everybody's time.
Almost all of you fail. The requirements clearly say that for multiples of 3 you are suppose to replace the number and since it is part of the same sentence you can suppose they mean the same for multiples of five. However multiples of both three and five are a totally different requirement and should be printed in addition to the times the multiples of 3 or 5 are printed.
You you could just chalk it up to bad requirements from the user ;)
will dieterich on February 27, 2007 8:26 AM /**
* Faster for a small amount of recursions, breaks without error for larger recursions (in php4)
*/
function fizzBuzzCounter($i=1)
{
if($i100)return false;else $s='';
if($i%3===0)$s = 'Fizz';
if($i%5===0)$s .= 'Buzz';
echo ($s===''?$i:$s)."br/";
return fizzBuzzCounter(++$i);
}
fizzBuzzCounter();
/**
* The obvious solution, alot faster in php5, can handle larger numbers
*/
for($i=1;$i=100;$i++)
{
if($i%3===0 || $i%5===0)
{
if($i%3===0) echo 'Fizz';
if($i%5===0) echo 'Buzz';
}
else
{
echo $i;
}
echo "br/";
}
Wow, double error... I meant to type "A" instead of "B".
And I got lost in my pedantics. You do need to check all 4 cards.
Since, if a vowel is on either side you have to have even on the other... if you have even on one side, the other must therefore be a vowel. And since anything not a vowel is a consonant, and anything not even is odd (ignoring weird cases like "Y" being sometimes one or another), you end up with all 4 cases covered in your theory.
For exampe: If you have the following set A/2, B/2, 2/D, 3/D.
You only check the "A" and "3" card, and your theory looks good.
Except there's an even number on the 3rd card ("2/D"), but there's not a vowel on the back, and you didn't check it, so you missed it.
You missed it - Theory wasn't adequately tested.
@zetaprime, sure it does, the whole point is that something is wrong in your education system, it seem to concentrate on graduating people with no skills.
The US doesn't even have a decent public school system, or a decent public healthcare system, of course these things have a direct impact on the quality of graduates.
Do you even know how much you spend on the military ? It's completely insane amounts. You alone stand for 1/3 of worlds total military spendings, and thats with less than 10% of the worlds population.
The US is not what I would call a modern country, you may have the gadgets and a great corporate climate but you fail to realize that it's the people that is the country, I can give you a million examples of this but that's a completely different discussion.
The military spendings have a LOT to do with the state of your schools today.
asking candidates to submit a page or so of what they consider to be
"good code". I don't mind if they wrote it or not,
All the better if they didn't, since it would indicate that they actually read other peoples' code.
chuck on February 27, 2007 8:36 AM"the count on February 27, 2007 08:20 AM"
are you using employment agencies or are you advertising directly?
if you are using agencies, it could simply be a case of the agencies not giving the candidate the full picture, in the hope that they'll slip under the radar, and Mr Agent will get his/her 10% commission.
that does happen a lot , and its not the candidates fault sometimes.
I certainly agree with the fizzbuzz test in terms of knowing basic things.
However, on the other hand, there's a difference between not knowing specific code/syntax, and not being able to learn it quickly if the need arises.
If you just don't have the mind for the programming, then it doesn't matter what language you use: your code is going to be confusing, messy, and very difficult for anyone else to maintain or build upon.
Mal on February 27, 2007 8:39 AMI've written one student compiler, a Prolog to C translator, numerous small interpreters, major C++ and ksh programs and subsystems, many of which are probably still running in systems around the world. By most standards (faults, easy to maintain, reusable parts), my code has been excellent. Although I would not have trouble with the FizzBuzz program, I do have trouble producing even some simple programs in 10 minutes while someone waits across the table. I suspect that many who can do this produce crap software, because they are willing to start coding before doing any analysis or design.
Jack on February 27, 2007 8:41 AMDifferent perl version. Won't guarantee it's correct, not having a perl runtime on this machine. It's more correct than other solutions I've seen though
for($i = 1; $i = 100; $i++)
{
$out = "";
$out .= (($i % 3) == 0) ? "fizz" : "";
$out .= (($i % 5) == 0) ? "buzz" : "";
$out .= ($out == "") ? $i : "";
print $out;
}
select case when mod(rownum,5) = 0 and mod(rownum,3) = 0 THEN 'FIZZBUZZ'
When mod(rownum,3) = 0 then 'FIZZ'
when mod(rownum,5) = 0 then 'BUZZ'
else to_char(rownum)
end num_fizz_buzz
from all_objects
where rownum = 100
I had a programming interview recently...I really wish they had asked me the FizzBuzz question. Horrible round table generic questions that don't prove, to any measurable degree, my capabilities as a programmer.
Chris on February 27, 2007 8:44 AM"Do you even know how much you spend on the military ?"
thats because the EU doesnt spend its fair share on defence, and thus uses the U.S. military umbrella. therefore, the EU can spend money on welfare, socialised health and very little on defence. so , the argument is somewhat unfair when you stand back and look at the bigger picture.
So, you want a real Professional Association for Software Engineers, eh?
Some places are starting this. For example, the Canadian Council of Professional Engineers has started to certify Software Engineering as an actual Engineering discipline. (Like Civil, Mechanical, Electrical, etc.) That means that you will have to do the following to call yourself a Software Engineer in Canada:
1. Get a 4-year degree, or 5 with co-op.
2. Spend 4 years under the guidance of other Professional Engineers.
3. Advance your skills over those four years.
4. Take a Professional Practice exam.
5. Have your character vouched for by four existing P.Engs.
By the way, there's no damned way you'd use that swapping trick on an embedded system. You're just asking for a world of pain.
First, there's the obvious problem with overflow. Let's say you want to swap 212 and 75 on an 8-bit system. Oops, you've just over-written your program somewhere.
Second, if you try to use cute tricks like that, there's a chance that you'll get interrupted in the middle and end up with the wrong values in your two variables. You can end up writing garbage - sometimes to ports. The correct answer is "You wouldn't do that. It's irresponsible."
It's like the
while( *p++ = *s++ );
strcpy code. Yeah, it works, but it's the worst code in the world.
themagni on February 27, 2007 8:47 AMSimple C answer:
for(i=1 ; i 101 ; i++){
printf("%d%s%s\n", i, i%3 ? "" : "fizz", i%5 ? "" : "buzz");
}
It's disgusting how many wrong solutions there are to FizzBuzz on this page..
for(int i = 0; i 100; i++){
if(i % 3 == 0)
printf("Fizz");
if(i % 5 == 0)
printf("Buzz");
else
printf("%d", i);
printf("\n");
}
Chris I haven't seen the card one either, but I don't think you have to flip more than A and 3.
You're testing "if there is a vowel, the number must be even" which doesn't care what number pairs w/ consonants.
So A must be flipped to verify that the other side is even. 3 must be flipped to verify that the other side is NOT a vowel.
But there's no need to check B - it has no vowel.
I assume the "trick" to the problem is the 2 card. You first think "Oh it's even so I have to flip it." But you don't.
If you flip it, what do you get? If it's a consonant, you haven't disproved the theory, because it's okay for a consonant to pair with an even number. If you see a vowel, you have some additional annecdotal evidence to support your theory, but nothing that really means anything.
I must not be in the top 0.5% of programmers, because I've been on more than one or two job inteviews... and I tell you, most of them were terrible at assessing my abilities to think and to code.
After walking out of several interviews convinced the company had done nothing to distinguish me from a tree stump, I got to the point where I almost wanted to shake the worst interviewers and shout "ASK ME SOMETHING HARD!"
I think the only real solution is to make programmers be licensed professionals that need to periodically prove that they have the skills their resume says they do.
I envision something like the Blacksmith Guilds of old ;)
Karthik on February 27, 2007 8:52 AMswapping without using a temporary generates more code than using a temporary.
http://www.codingaway.com/2007/01/31/is-swap-without-temporary-a-good-idea/
Its wrong to think of solutions from programming perspective. I mean why should I know how to use recursion to solve a "real" problem?
First we should be able to define the problem then find the best possible solution..recursion or no recursion.
"Jon Vaughan on February 27, 2007 08:43 AM"
thats pretty easy. just iterate through the string char by char , build substrings on the fly if the previous char is the same - and the end you'll have a bunch of substrings (maybe a multi-dim array) and just compare the sizes of these.
AABBBBBCCCCDDDEEEEEEEE
$string[0]="AA";
$string[1]="BBBB";
$string[2]="CCCC";
$string[3]="DDD";
etc..
I had to do the swap-2-numbers thing back in 1973 on a PDP-11. I had forgotten the method. As for recursion, it's good for tree population and list containers.
"mtrpcic on February 27, 2007 08:51 AM"
you're wrong. you didnt start at 1
I 'd love to see a COBOL implementation of Fizz Buzz here.
And dont cheat. Code must be runnable with cut-paste. You know what i mean. Mandatory divisions-sections, proper line positioning and stuff.. He he...
Assume the ANSI 85 standard. Anyone?
Matthew,
In your perl version, you could have done this, to be more perlish of course.. (I prefer readability/cleanliness/maintainability, hence I use python).
instead of:
$out .= (($i % 3) == 0) ? "fizz" : "";
you could just use:
$out .= (!($i%3)) ? "fizz" : "";
This response is only to point out the above, I'm not criticising or 'correcting' anything.. just pointing out that in perl as with other languages doing a simple NOT operand removes unnecessary right side evaluation operators. The thing that bothers me still about perl is that in my solution, the ratio of punctuation vs. alphanumerics is greater than 2:1 $.=(!($%))?"":""; : out3fizz
For the guy who wrote the "executable line noise" Perl version: I'm glad you program in Python.
use strict;
use warnings;
for my $i (1..100) {
my $div3 = $i % 3 == 0;
my $div5 = $i % 5 == 0;
if ( $div3 and $div5 ) {
print 'fizzbuzz';
}
elsif ($div3) {
print 'fizz';
}
elsif ($div5) {
print 'buzz';
}
else {
print $i;
}
print "\n";
}
It's not clever, but I'll be able to read it easily 6 months or a year later.
If you insist on the ternary operator, try this:
for my $i (1..100) {
my $div3 = $i % 3 == 0;
my $div5 = $i % 5 == 0;
print +($div3 and $div5) ? 'fizzbuzz' :
$div3 ? 'fizz' :
$div5 ? 'buzz' :
$i;
print "\n";
}
My MS SQL Solution...(im a newbie programmer, so its probably not the most efficent solution!)
declare @i int
declare @text varchar(50)
declare @i3 int
declare @i5 int
set @i=1
while @i = 1000
begin
set @text = ''
set @i3 = @i/3
set @i5 = @i/5
if (@i3*3=@i) and (@i5*5@i)
begin
set @text = 'Fizz'
end
if (@i3*3@i) and (@i5*5=@i)
begin
set @text = 'Buzz'
end
if (@i3*3=@i) and (@i5*5=@i)
begin
set @text = 'FizzBuzz'
end
print convert(varchar(5),@i) + ' - ' + @text
set @i = @i + 1
end
Any comments id be grateful - MattConway@GMail.com
Matt Conway on February 27, 2007 9:11 AMMy favorite posters are those who lambast others' fizzbuzz programs, then go post their own incorrect solutions.
Like "mtrpcic" above. Too funny...
Yeah, I can write a Sieve of Eratosthenes, but why are you only sifting out two primes? Well, you ask a silly question, you get a silly answer. We don't even need looping or conditional statements for this one.
print 1
print 2
print "Fizz"
print 4
print "Buzz"
print "Fizz"
print 7
print 8
...etc, etc.
?php
for ($i=1; $i = 100; $i++) {
echo $i;
if ($i%3 == 0) {
echo " fizz";
}
if ($i%5 == 0) {
echo " buzz";
}
echo "br /";
}
?
netron:
Actually, that's a pretty inefficient way to do it.
Bah, was going to explain, but writing code'll be easier:
public int GetLargestSequence(string input)
{
int largest = count = 1;
char largestChar = input[0];
for (int i = 1; i input.Length; i++)
{
if (input[i] != input[i - 1])
{
if (count largest)
{
largest = count;
largestChar = input[i - 1];
}
count = 0;
}
count++;
}
}
Should work anyway, not tested... web forms don't compile well. ;) No need to keep a bunch of string arrays around when you're just counting something.
Telos on February 27, 2007 9:15 AMMy first attempt:
(1..100).each do |i| puts i % 3 == 0 ? (i % 5 == 0 ? "FizzBuzz" : "Fizz") : (i % 5 == 0 ? "Buzz" : i) end
It's ugly, but the whole point was your first non-tested 'on the paper' result :)
mtrpcic: Yeah, it is.. but yours is wrong also since the spec was 1 to 100, not 0 to 99.
Peter Cooper on February 27, 2007 9:16 AMFH wrote: "On recursion, I stand by my advice to students. You should know what it is, how it works, and how to program it. But you should _never_ use it in production code, because whoever maintains it may not grasp what is going on."
"Never" is a bit strong, but think you are closer to right than to wrong on this one. Perhaps in a perfect world everyone would be fluent in recursion, but in the real world you are likely to be causing maintenance problems for all but an elite few if you use it.
More importantly, you are clearly thinking about maintenance issues and teaching to them in class. If your students graduate and find themselves in a situation you didn't cover in class, which they will, then at least their heads will be in the right place to start with.
T.E.D. on February 27, 2007 9:21 AMThe definitive C++ solution:
#include iostream
template int n, int m3, int m5
struct fizzbuzz
{
fizzbuzzn-1, (n-1)%3, (n-1)%5 fb;
fizzbuzz()
{ std::cout n std::endl; }
};
template int n
struct fizzbuzzn, 0, 0
{
fizzbuzzn-1, (n-1)%3, (n-1)%5 fb;
fizzbuzz()
{ std::cout "FizzBuzz" std::endl; }
};
template int n, int p
struct fizzbuzzn, 0, p
{
fizzbuzzn-1, (n-1)%3, (n-1)%5 fb;
fizzbuzz()
{ std::cout "Fizz" std::endl; }
};
template int n, int p
struct fizzbuzzn, p, 0
{
fizzbuzzn-1, (n-1)%3, (n-1)%5 fb;
fizzbuzz()
{ std::cout "Buzz" std::endl; }
};
template
struct fizzbuzz0,0,0
{
fizzbuzz()
{ std::cout 0 std::endl; }
};
template int n
struct fb_run
{
fizzbuzzn, n%3, n%5 fb;
};
int main()
{
fb_run100 fb;
}
It may be a bit long.
Emmanuel Deloget on February 27, 2007 9:26 AM@Patrick
But there's no need to check B - it has no vowel.
You're right. I reread it, and caught myself expanding "one side" and "other side" into an iff scenario.
The original premise is: "one side vowel" - "other side even"
The only other logically equivalent statement is: "one side not even" - "other side not vowel" (equivalent to "one side odd" - "other side consonant")
So, you'd have to check vowels and odds, or "A" and "3"
My original problem with the question still holds though. You have to assume a particular level of precision in writing on the probelm writer. Do they really know the difference between if and iff?
You might be caught on an off day for that sort of a problem. Will you be doing minimal test scenarios yourself all the time with no opportunity to come back when you're feeling "not so dumb"? etc
Uh, someone ordered an x86 assembly version?
(Linux Syscalls/NASM/ELF)
%macro write 2
; Argument 0: char* string to write
; Argument 1: length of string
mov edx, %2 ; edx = length
mov ecx, %1 ; ecx = string
mov ebx, 1 ; ebx = "stdout" stream
mov eax, 4 ; eax = "WRITE"
int 0x80 ; Linux syscall
%endmacro
section .rodata
FIZZ: db "Fizz"
BUZZ: db "Buzz"
NL: db 0xa
section .bss
i: resb 1
c: resb 1
tmp: resb 1
section .text
global _start
_start:
mov byte [i], 1
forloop:
cmp byte [i], 100
jbe not_exit
jmp exit
not_exit:
; if (i % 3 == 0)
mov al, [i]
xor ah, ah
mov cl, 3
div cl
test ah, ah
jnz trybuzz
write FIZZ, 4
; if (i % 5 == 0)
mov al, [i]
mov cl, 5
div cl
test ah, ah
jnz not_buzz
write BUZZ, 4
not_buzz:
jmp continue
trybuzz:
; if (i % 5 == 0)
mov al, [i]
xor ah, ah
mov cl, 5
div cl
test ah, ah
jnz printnum
write BUZZ, 4
jmp continue
printnum:
; Write the number i
mov al, [i]
xor ah, ah
cmp al, 100
jl tens
mov cl, 100
div cl ; ah = al % 100
add al, '0'
mov [c], al
mov [tmp], ah
write c, 1
mov al, [tmp]
xor ah, ah
tens:
mov al, [i]
cmp al, 10
jl ones
mov cl, 10
div cl ; ah = al % 10
add al, '0'
mov [c], al
mov [tmp], ah
write c, 1
mov al, [tmp]
xor ah, ah
ones:
add al, '0'
mov [c], al
write c, 1
continue:
write NL, 1
inc byte [i]
jmp forloop
exit:
mov ebx, 0
mov eax, 1
int 0x80
; OH MY GOD THAT TOOK AGES!!!!!!
Matt Giuca on February 27, 2007 9:32 AMDavid,
Regarding the executable line noise version. It was intentionally ugly. When I professionally worked in perl environments (for about 8 years solid), my perl was quite clean and organised. Were it not for the excessive perl punctuation you might confuse it with clean Java code. I know I could've written it over a series of lines, etc., but that wasn't the point. I'm not a big fan of obfuscated code but in something as simple as the fizzbuzz exercise, I was just pointing out that it can be accomplished in what is essentially one command, not actually a code block. The only reason that the {}'s were included is because it is necessary in a for loop.
And yes, I agree that 3-level deep nested in-line conditionals are ugly and if I ever found any used in production code within our subversion repository, I'd have the person responsible taken out behind the shed and thrashed with a switch.
Eric
Eric Elinow on February 27, 2007 9:33 AMYour tests do indeed screen out people who cannot code without a computer. If part of the job requirement is writing coding without a computer then I guess this is a good test.
Most programmers (myself included) write code on a computer and don't have the visualization skills to program on paper. Whenever I get these questions in an interview I reply that I don't code on paper and if they want an example of my coding, they can give me a problem to solve and a computer to solve it on.
Bob on February 27, 2007 9:33 AMWow, and the elimination of indentation made the whole thing look like garbage!
Matt Giuca on February 27, 2007 9:33 AMR. Butler: There's a typo in the code you refer to (by the original poster of that code).
The actual swap logic uses only XOR:
A = 5
B = 10
A = A XOR B // A == 15, B == 10
B = B XOR A // A == 15, B == 5
A = A XOR B // A == 10, B == 5
As you can see, the swap does occur. :-)
KenW on February 27, 2007 9:34 AM public abstract class Factory
{
public string ToString(char[] chars)
{
return new string(chars);
}
}
public class FizzFactory : Factory
{
private const char F = 'F';
private const char i = 'i';
private const char z = 'z';
public bool isFizz(int input)
{
if (input == 3) return true;
else if (input == 6) return true;
else if (input == 9) return true;
else if (input == 12) return true;
else if (input == 15) return true;
else if (input == 18) return true;
else if (input == 21) return true;
else if (input == 24) return true;
else if (input == 28) return true;
else if (input == 30) return true;
else if (input == 33) return true;
else if (input == 36) return true;
else if (input == 39) return true;
else if (input == 42) return true;
else if (input == 45) return true;
else if (input == 48) return true;
else if (input == 51) return true;
else if (input == 54) return true;
else if (input == 57) return true;
else if (input == 60) return true;
else if (input == 63) return true;
else if (input == 66) return true;
else if (input == 69) return true;
else if (input == 72) return true;
else if (input == 75) return true;
else if (input == 78) return true;
else if (input == 81) return true;
else if (input == 84) return true;
else if (input == 87) return true;
else if (input == 90) return true;
else if (input == 93) return true;
else if (input == 96) return true;
else if (input == 99) return true;
else return false;
}
public string GetFizz()
{
return base.ToString(new char[4] { F, i, z, z });
}
}
public class BuzzFactory : Factory
{
private const char B = 'B';
private const char u = 'u';
private const char z = 'z';
public bool isBuzz(int input)
{
if (input == 5) return true;
else if (input == 10) return true;
else if (input == 15) return true;
else if (input == 20) return true;
else if (input == 25) return true;
else if (input == 30) return true;
else if (input == 35) return true;
else if (input == 40) return true;
else if (input == 45) return true;
else if (input == 50) return true;
else if (input == 55) return true;
else if (input == 60) return true;
else if (input == 65) return true;
else if (input == 70) return true;
else if (input == 75) return true;
else if (input == 80) return true;
else if (input == 85) return true;
else if (input == 90) return true;
else if (input == 95) return true;
else if (input == 100) return true;
else return false;
}
public string GetBuzz()
{
return base.ToString(new char[4] { B, u, z, z });
}
}
public delegate void FizzBuzzWriter(string input);
public class Looper
{
private FizzFactory Fizz;
private BuzzFactory Buzz;
public event FizzBuzzWriter OnFizzBuzz;
public Looper(Factory fizzFact, Factory buzzFact)
{
Fizz = (FizzFactory) fizzFact;
Buzz = (BuzzFactory) buzzFact;
}
public void execute(int start, int finish)
{
for(int i = start; i=finish; i++)
{
string val = String.Empty;
if (Fizz.isFizz(i)) val += Fizz.GetFizz();
if (Buzz.isBuzz(i)) val += Buzz.GetBuzz();
if (val == String.Empty) val = i.ToString();
if (OnFizzBuzz != null) OnFizzBuzz(val);
}
}
}
public class TheFizzBuzzProgram
{
public static void main(string[] args)
{
Looper l = new Looper(new FizzFactory(), new BuzzFactory());
l.OnFizzBuzz += new FizzBuzzWriter(l_OnFizzBuzz);
l.execute(1,100);
}
static void l_OnFizzBuzz(string input)
{
Console.Write(input + Environment.NewLine);
}
}
I don't believe the 199 out of 200 statement.
My experience as a manager and programmer is that
only a very few candidates can't program.
I've had exactly one instance in interveiwing
about 200 people over the years where the person
said they knew SQL and when I asked them to write a simple
SELECT statement on the board, they admitted they didn't know
SQL *that* well.
Now I have seen lots of programmers that simply were very poor programmers. It is rare to find a self motivated, can-do type of programmer that comes up with a good solution without any coaching.
rkeene on February 27, 2007 9:41 AMI like FizzBuzz, though there's something to be said for jumping straight to a pointer/recursion screening question.
I'm not so fond of the "swap two variables without using a temporary variable" question. There's several possible outcomes of asking it.
1) The candidate can answer the question correctly:
1a) ...because the candidate has seen the trick before. Chance of hiring: Unchanged, because we've learned nothing useful.
1b) ...because the candidate has enough mathematical sophistication to solve the problem from scratch. (All you need is an algebra with a binary operator and inverse elements[1].) Chance of hiring: Increased.
2) The candidate can't answer the question correctly:
2a) ...because the candidate is a poor programmer. Chance of hiring: Decreased.
2b) ...because the candidate is a good programmer who doesn't see the trick, and isn't quite clever enough to derive it from first principles. Chance of hiring: Increased (for most jobs).
The scoring matrix is all screwy here: Some bad candidates answer the question well (a subset of 1a), and some potentially good candidates miss it (2b). Now, you could argue that for some jobs (say, programming at Google), you don't mind losing the competent but mathematically weak programmers in group 2b. In that case, the scoring matrix is a little better, but it still doesn't distinguish between group 1a and group 1b.
If you really want to hire exclusively from group 1b, you'd get better results by asking a straight-out math question.
[1] The inverse elements allow you to rewrite "b=a-b" as "b=(-b)+a", which gets rid of the compiler-allocated temporary variable that some architectures require for "b=a-b". Of course, signed C integers aren't closed under addition, so you're better off using xor for this trick.
emk on February 27, 2007 9:45 AMIt's not "can you program in X language" but "Can you program in ANY language" or even a psuedocode that is reasonably similar to the target language?
If the target language is C, don't fault a guy who hasn't touched C in 3 years and forgot the syntax of a for loop. If he can show you he knows the key concepts of programming in a procedural language don't reject him out of hand.
If the target language is Prolog or LISP, knowing ONLY C or another procedural language may not be a lot of help.
Two exceptions: If you need him to be pumping out code at full speed in the first 2 days, you need someone who really knows the language now. If you need full speed within a week, you know someone who really knew the language at one time. With anyone else, give them a couple weeks and they'll be up to speed.
davidwr on February 27, 2007 9:46 AMThis post is like making a comment on a Star Trek forum about the guy in the yellow shirt that dies on the away mission.
Steve Steiner on February 27, 2007 9:46 AMAlright, well, as a current computer science major with 8 years real work experience under my belt, I can tell you this: People are persistent. They're just not willing to admit they cannot do something. Often times this means some CS majors spend 40 hours on simple 100-200 level projects... and pass the class. You'd think the theory would weed them out, but let's face it, college is geared towards those who study for the test. After the test is complete, who cares, right? "I'll never see recursion again!"... uh... no. I'm actually astonished how many of your commentators have already said they don't use it. Some have gone so far as to say that even if you do understand recursion and it makes the best code, it's better not to use it for the sake of the idiot they hire to maintain your code...
... What the hell? I'm a web developer and I use recursion a great deal, and in ways most people wouldn't consider. I understand that it can actually be a performance hog many times, but if you have a deep underlying knowledge of how the server handles memory, this shouldn't be a problem.
Where is the respect for our trade? Do we really want to cater software development to the lowest common denominator of coders? Every single test I've taken to land a job has been so easy it made me insulted they asked. I decided to take an internship this past summer, for example. In one of my interviews (as a web developer for the Tools department of AOL), they tested me to ensure I knew that GET and POST existed... not when to use them... not how to use them... not even what they were. They just wanted to know if I knew they existed.
As a web developer, I almost assume any applicant would know this just by applying for the job.
I didn't take that job. That kind of question almost guarantees bitch work. Instead I went with the interviewer who asked me questions I didnt know... like what port is used for DNS UDP. And sure enough, that job gave me more freedom, and plenty of good honest to god work experience. I talked to the intern from tools, and yeah, bitch work. In fact, I received 4 internship offers from AOL that summer and two job offers which I turned down... more than any other intern there to my knowledge. And what's my college GPA?
...
...
2.10
Yeah, I'm not doing so hot in school. Why? I can't really give a good excuse. Laziness is my only reason. I can't seem to drag myself to attend a class I can just as easily teach myself in a matter of days yet somehow takes our class an entire semester and people still do not get it.
Some people, such as my roomate right now, will graduate with near 4.0 GPA's and will not be expert programmers. What a waste of 4 years, if you ask me.
Rafajafar on February 27, 2007 9:46 AMKris, you didn't read the requirements, x is not printed if anything else is. Understand the requirements.
zetaprime on February 27, 2007 9:47 AMI wrote this in C++ ....it compile right and seemed output to the screen correctly. I'm no computer programmer, I just fiddle around with stuff.
I timed myself it took 25 to 30 minutes.
#include iostream
using namespace std;
int main()
{
int counter = 1;
int three;
int five;
while(counter 101)
{
three = counter % 3;
five = counter % 5;
if(three == 0 five == 0)
{
cout "FizzBuzz" endl;
}
if (three != 0 five != 0)
{
cout counter endl;
}
if (three == 0 five != 0)
{
cout "Fizz" endl;
}
if (three != 0 five == 0)
{
cout "Buzz" endl;
}
counter++;
}
system("PAUSE");
}
Why the hostility to these questions?
They are quite appropriate if you accept a variety of answers; I would take anything that showed the ability and inclination to think.
I would expect them to to get the Fizzbuzz problem logically correct, but not worry too much about syntactic details.
I would happily accept "Hmm. I'm not sure how to swap two integers in place, but I bet there is some sort of bitwise trickery that can be used".
If I asked someone to write a recursive implementation of (say) the Fibonacci sequence, I would expect them to be able to pull it off-- but I would be overjoyed if they said "You know, this degenrates into a O(2^n) problem when implemented recursively due to recalculation. It would be better to implement it iteratively. Or if you insist on recursion, you could get O(n) time by using memoization".
THAT is why you ask these questions. To find the people who can solve problems and propose solutions that you hadn't foreseen. Sure, there is a place for code monkeys who can grab values from a form and stuff them in a database. But I will MAKE a place for a programmer with insight, problem solving skills and a genuine love of their craft.
Silas on February 27, 2007 9:54 AMgcc actually compiles more efficient code when using a temp variable than it does if you use the xor trick.
--- swap.s Sun Feb 25 02:06:34 2007
+++ xor-swap.s Sun Feb 25 02:05:52 2007
@@ -24,9 +24,12 @@
call gets
movl %eax, (%esp)
call atoi
+ orl %eax, %ebx
addl $12, %esp
- pushl %ebx
+ xorl %ebx, %eax
pushl %eax
+ xorl %eax, %ebx
+ pushl %ebx
pushl $.LC0
call printf
leal -8(%ebp), %esp
The xor thing is one little antique trick which is completely and utterly pointless to ask about in an interview.
Stewie on February 27, 2007 9:55 AMI took me 4 minutes to write the working code in PL/SQL. But I am not a programmer, just a DBA.
I wanted to test myself to he how good or bad I am.
What do you have to be afraid of - failure?
michael on February 27, 2007 9:57 AMOverall this doesn't surprise me too much.
It's amusing that various answers seem to indicate the writer didn't actually read the question. Well, I assume that if you dare to comment with code you solved your *understanding* correctly, anyhow...
I'm not sure how fair the FizzBuzz test is, not because of the test, but because it is written. I always hated having to write code on exams (especially without scratch paper) because when you type code, as one always does, you can instantly spot spot mistakes, convoluted logic (I sometimes annoy friends by simplifying their logic into a fraction of its original size), easily redundant code (and unnecessary expensive instructions -- don't you know modulos are dozens of clocks, people?), you can restructure typed code, throw evaluations into or out of loops in seconds.
Not only that, you have brain left over to run all sorts of simple heuristic checks out, visual checks (I'm elsing that? duuuuh, get more coffee!) be it out of experience or a bordom of sorts.
But mostly there's just the extra hurdle to paper. You are suddenly required to to keep several complete solutions in your head before you even put pen to paper. Because I have my pride - I'm not going to give you a stupid solution.
I much, much prefer even notepad to paper. I think many would agree, especially when he logic to be worked out involves several not-completely-trivivial bits. Fizzbuzz really only has one, some exclusiveness you need to consider.
scarfboy on February 27, 2007 9:59 AMNick Franceschina, you rock dude. Made me laugh so hard :D
cwiz on February 27, 2007 10:03 AMWow, Look at all the different languages people have used to do the Fizz Buzz and some have done it poorly. Does it still make them eligible for the job? And this is when the blog(post) by Jeff wasn't even about writing the solution. :)
Kashif Razzaqui on February 27, 2007 10:07 AMI'm so amazed that *graduates* actually fail these miserable tests when the skill level required to hold a programming job is usually so beneath that of a compsci degree -- That is, once you learn a programming language that's actually marketable and get going with the productivity imperative. Should we conclude that the market is saturated with pretenders applying for every computing job around? I wonder why don't they postulate for sales job, instead, where salaries are attractive and pretending can actually be a plus. Hm, I might be getting a bit cynical here... Sorry 'bout that.
To me, these "observations" sound more like a war stories than anything else. The kind told by disenchanted employers wishing for affordable "plug'n play" elite programmers they haven't found; or by proud, devoted application developers in need of shock therapy.
I would have thought that the world was plenty with decent programmers who could do very decent work within somewhat decent working environments. Otherwise, finding good work wouldn't be such a hassle. Perhaps there's a mismatch in the way employers and job applicants are looking for each other... Judging by the various ways each of us answered to this post, it's clear that we don't all agree about what makes a good programmer for hire. It seems to depend on the job and, mostly, on our own background and perceptions.
In my case, my personal best bet would be to set up a nice working environment, hire bright enough people and let them grow. Since our profession is being mostly about shifting our understanding from the consumer to the machine, from architecture and logic to technology and implementation, I would rather build a team with complementary skills rather than give a job to every member of the LISP club who has already built a compiler. There's more than one way to be a good programmer.
stochastio on February 27, 2007 10:07 AMI can unfortunately say that this applies to all of engineering, not just software. I work in embedded control systems where a lot of Mechanical types end up, and most of the candidates we interview end up knowing nothing of either discipline. I've met guys with graduate degrees from serious big name schools who can't solve some really pathetic problems.
The real lesson here is that how a person looks on paper will rarely reflect their actual abilities.
Dan on February 27, 2007 10:10 AMThe comments to this entry are closed.
|
|
Traffic Stats |