Why Can't Programmers.. Program?

February 26, 2007

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.

Posted by Jeff Atwood
466 Comments

I've only been programming a little under a year, but I don't think that I could do the FizzBuzz program off the top of my head. Why? Well, the idea of the loop is simple enough, however I have NEVER needed to know if a number was divisible by another, so I have no idea what function finds that for me. If I were given the chance to look that part up, then I wouldn't have any trouble.

jread on February 28, 2007 7:43 AM

Amazing. The comments on this thread are full of people criticizing the article, but it seems like *most* of the code examples posted here appear to completely back it up! It is shocking how many of the "coders" that posted here did not do simple things like initialize their variables - resulting in code that counts from 0-100 (read that as false positives since 0 mod 3 and 0 mod 5 = 0) - or display ALL numbers INCLUDING multiples of 3 and 5.
Maybe the problem is not so much that most "programmers" can't code, but that they can't follow directions.

blakhatt on February 28, 2007 7:44 AM

Ignoring the language for now, the simplest way to do this is IMO:

for (int i = 0; i 101; ++i)
{
if (i % 3 == 0) then
{
printf("Fizz");
}
else
{
if (i % 5 == 0) then
{
printf("Buzz");
}
else
{
printf("%d", i);
}
}
}

Bassam on February 28, 2007 7:50 AM

Here's a more elegant MSSQL version that improves on the one above by using fewer variables, fewer checks and SELECT instead of SET (SELECT is apparently a little faster).

DECLARE @i int
DECLARE @text varchar (8)

SELECT @i = 1

WHILE @i 101
BEGIN
SELECT @text = ''

IF (@i % 3)
SELECT @text = 'Fizz'
IF (@i % 5)
SELECT @text = @text + 'Buzz'
IF (@text = '')
SELECT @text = @i

PRINT @text

SELECT @i = @i + 1
END

bob on February 28, 2007 7:50 AM

WHERE IS THE COBOL?!?!?

Man, it's been years...

*************************************
*
*
* This is what a cobol program used to look like....
*
*
**************************************

*First you had your variable declaraction section or something...

WS-COUNT-LOOP = TYPE INTEGER;

bla bla bla!! Man, I can't remember it at all... had to learn that stuff freshman year...

Schmeckendeugler on February 28, 2007 7:53 AM

^ Need I say more? ^

blakhatt on February 28, 2007 7:54 AM

its probably due to the fact that most web app programmers dont have to do lame-ish tasks like that

tj on February 28, 2007 7:58 AM

This is so demonstrative. How many programmers does it take to read the requirements? I thought they were painfully obvious. It's not like in real life where the user just says:

"I want something that will let me take my data out of AutoCad2000 and enter it into our custom database written in 1988 by a lame-ass who can't program. By the way, I won't be available for comment, and I need it done in two weeks."

While I'm aware you could probably do something to short these if's using bit math, this is my unoptimized solution:

// Run with cscript/E:JScript [filename]
for(i = 1; i 101; i++)
{
if(i 15)
WScript.Echo("FizzBuzz\n");
else if(i 3)
WScript.Echo("Fizz\n");
else if(i % 5)
WScript.Echo("Buzz\n");
else
WScript.Echo(i+"\n");
}

// compile with dmd -release -O [filename]
for(int i = 1; i 101; i++)
{
if(i 15)
printf("FizzBuzz");
else if(i 3)
printf("Fizz");
else if(i % 5)
printf("Buzz");
else
printf("%d",i);
printf("\n");
}

// Note that any case where you have a 2^x - 1, you can use ''
// instead of %, and it'll run faster. An optimal solution would
// trim out the branching, probably with some bitmath.

// After 0x0F comes 0x10.

// Right now on my spare time I'm the project maintainer for Walnut:
// http://dsource.org/projects/walnut
// A JScript engine. It's a mature project, and I'm implementing
// a COM client for it.

// I'm currently employed as an office assistant, because I can't get
// a job as a programmer. You can reach me at murpsoft@hotmail.com
// I am willing to move, but prefer to telecommute.

Dan on February 28, 2007 8:00 AM

Public Function BizzFuzz(ByVal int As Integer)
Dim i As Integer
For i = 1 To int
If (i Mod 3 = 0) And (i Mod 5 = 0) Then
Console.WriteLine("FizzBuzz")
ElseIf i Mod 3 = 0 Then
Console.WriteLine("Fizz")
ElseIf i Mod 5 = 0 Then
Console.WriteLine("Buzz")
Else
Console.WriteLine(i)
End If
Next
End Function

Frank on February 28, 2007 8:05 AM

A little late; but I figured I'd throw in a CL version:


(loop for i from 1 to 100
do
(or
(some #'identity
(list
(if (zerop (mod i 3)) (progn (format t "Fizz") t))
(if (zerop (mod i 5)) (progn (format t "Buzz") t))))
(format t "~A" i))
(terpri))

Matt on February 28, 2007 8:13 AM

Python one-liner:
print map(lambda x: 'FizzBuzz' if x%15 == 0 else 'Fizz' if x%3 == 0 else 'Buzz' if x%5 == 0 else x, range(100))

This could probably be replaced with a list comprehension.

Nathan Forget on February 28, 2007 8:14 AM

Speaking as a newly hired entry-level programmer, I think this post is completely ridiculous. I wasn't able to answer your FizzBuzz question very quickly (although the logic of it was obvious), but I was recently hired by the IT division of a top I-banking company anyway. What's more, I don't think they cared if I could code that well yet. What's more than more, I think they were correct not to.

I'll be honest, I didn't think I would get the job. I'm not even a CS major (Math major, CS minor). But they hired me because I'm smart and demonstrably trainable, and have passions outside academia. Basically, I represent a low risk. They can train me however they need to and feel comfortable in the belief that I will be able to contribute. But the fact that they have to train me is not my fault. Schools don't teach students how to code anymore, don't you all know that? How can an institution like that keep up with all the changes in programming that happen so, so fast. Do you know how much php, ajax, C, C++, perl, FORTRAN, COBOL, or Ruby I was taught? None, nada, zilch. It was "on me" to learn these languages if I needed them for an assignment, which was rare. The only thing I was taught was Java, and not very much of it.

However, what I WAS taught was theory and architecture. Heaps, stacks, linked-lists, graphs, hash-tables, classes, inheritence, search trees, Big-O, min-cuts/max-flows, database management, logic and set-theory, optimization, and all the basics of data architecture. Hell, I know more Assembly than I do C++!

This knowledge spans all disciplines within computer science and any language. I might've gotten a job designing websites for a 2.0 or helping to manage a database for a bank. There's just no way to know how I was to focus my college studies, so I was given the big picture instead. I think this will work, I'll find out for sure soon enough.

Java:

String s[] = {null,null,"Fizz",null,"Buzz","Fizz",null,null,"Fizz","Buzz",null,"Fizz",null,null,"FizzBuzz"};
int i = 0;

for (int count = 1; count =100; count++)
{
if (i 15)
{
if (s[i] == null)
System.out.println(count);
else
System.out.println(s[i]);
}
else
i = 0;
i++;
}

FizzWhat? on February 28, 2007 8:26 AM

Python one-liner:
print map(lambda x: 'FizzBuzz' if x%15 == 0 else 'Fizz' if x%3 == 0 else 'Buzz' if x%5 == 0 else x, range(1, 101))

This could probably be replaced with a list comprehension.

Nathan Forget on February 28, 2007 8:31 AM

(awk)

BEGIN {
i = 0;
while (i100)
{
i=i+1;
if (int(i/3)*3==i int(i/5)*5==i)
{
print "FizzBuzz";
continue;
}
if (int(i/3)*3==i)
{
print "Fizz";
continue;
}
if (int(i/5)*5==i)
{
print "Buzz";
continue;
}
print i;
}

}

Merle Zimmermann on February 28, 2007 8:43 AM

bzzzt... another wrong answer Bassam! 1. You started at 0. 2. Your logic is wrong (what would 15 do?).

Okay, since I ended up posting, I'll post the code I jotted down when I read this post. (It took me about 4 min) (Perl)

for my $num (1..100) {
print $num if ($num % 3 and $num % 5);
print "Fizz" unless $num % 3;
print "Buzz" unless $num % 5;
print "\n";
}

I think it's fairly readable (especially compared to the other Perl solutions :P). In a real-world scenario, though, if code maintainers were not likely to know Perl well, I'd probably avoid the trailing-ifs and "unless" because I've seen these things confuse people.

I like the comments about asking questions of the interviewers regarding what to optimize for (readability? execution speed? brevity?) and whether this was likely to change, etc. Also, parameterizing the input instead of hard coding would possibly be a good way to do it (unless you had to do it in as short a time as possible). These little extra things (combined with, of course, a working program) would make you stand out in an interview.

Mark on February 28, 2007 8:43 AM

Jeff, having 'programmers' attempt to write this type of program in an interview surely will weed out a crap load of candidates...but just because you can write the FizzBuzz program within a couple of minutes on a piece of paper doesn't really mean much either.

From what I can see it only means you understand IF statements and comparison operators. I know designers who are crafy at coding JavaScript who can pull this program off in 5 minutes but I wouldn't dare consider them for a real programming job. Why? Well this is just really the tip of the ice-berg...and I liken being able to code this statement as someone capable of changing their car's oil. Which by the way a crap load of people can't do either. Of course would you call the few souls who do change their oil mechanics???

-Ralph

Ralph on February 28, 2007 8:53 AM

Jeff,

The ADO.NET Orcas Entity Data Model will significantly reduce the code required for both Fizzing and Buzzing activities. Additionally, you may gain value from the ASP.NET AJAX Framework, which can update your end user's page with Fizzes and Buzzes as they are computed.

Hope this helps,
Scott

Scott Guthrie on February 28, 2007 8:58 AM

I think little coding exercises like this are far more interesting that flash games and NSFW articles/pics to pass time...LETS HAVE MORE OF THEM!

~ Matt


?php
$x=1;
while ($x101) {
if ((($x%5) == 0) and (($x%3) == 0)){
print "five AND three /br";}
else if (($x%3) == 0) {
print "threebr/";}
else if (($x%5) == 0) {
print "fivebr /";}
else {
print "$xbr /";
}
$x += 1;
}
print "You truly are, the king of kings!";
?

Matt on February 28, 2007 8:58 AM

Because we all know how high the command is for TI-83 basic. :P

a=0
label a
a+1=a:a/3=b:int(b)=c:a/5=d:int(d)=e
if a100:then
stop:end
if b=c:then
if d=e:then
print "fizzbuzz":goto a:end
print "fizz":goto a:end
if d=e:then
print "buzz":goto a:end

Michael on February 28, 2007 8:59 AM

Far too many comments for me to read through, so forgive me if this has already been stated.

Regarding the no-temp-variable swapping: For one I don't think this says anything toward or against anyone's programming ability. Especially since the solution offered won't work in every case.

The biggest flaw with the plus/minus solution is that overflow can and will occur for large numbers. The better solution is to use three XOR operations. And even that obviously wont work for non-numeric variables (strings, objects, etc).

And it appalls me to see so many people actively not using loops and calculation in the FizzBuzz problem. (i.e. the people listing "print 1, print 2, print "fizz" .... etc.) If I were hiring a developer and had a candidate that said outright "I don't know" versus a person who did this, I'd take the "I don't know" guy/gal.

LightningStorm on February 28, 2007 9:07 AM

I agree with the one who says, if u want a good programmer, don't put the contraint (must hire only graduates), being one does not guarantee success at all. I code since 1990 and have seen lots of good software developers and most of them where just self-taught. Important organizations have lost worthy resources because they were asked to hire graduated people just to fulfill requirements for the job's description. FizzBuzz test can be a good thing but it cannot be the only thing to test a good programmer, because some clever minds owners that don't have resources to get a degree may be awaiting for someone to help them launch the rocket, then they will take you to mars and venus, who knows, but If you don't give the chance, someone else will do.

jotape on February 28, 2007 9:07 AM

The question I asked many candidates was

Write a function to test if the argument is part of the Fibonacci sequence.

Many candidates don't know where to start.

But not 199 out of 200.

Is HR not screening anyone out for you?

tim dugan on February 28, 2007 9:07 AM

Far too many comments for me to read through, so forgive me if this has already been stated.

Regarding the no-temp-variable swapping: For one I don't think this says anything toward or against anyone's programming ability. Especially since the solution offered won't work in every case.

The biggest flaw with the plus/minus solution is that overflow can and will occur for large numbers. The better solution is to use three XOR operations. And even that obviously wont work for non-numeric variables (strings, objects, etc).

And it appalls me to see so many people actively not using loops and calculation in the FizzBuzz problem. (i.e. the people listing "print 1, print 2, print "fizz" .... etc.) If I were hiring a developer and had a candidate that said outright "I don't know" versus a person who did this, I'd take the "I don't know" guy/gal.

LightningStorm on February 28, 2007 9:08 AM

i haven't used MOD since my vb.net class. and it's never come up in the real world so far, so, i might just have tanked on the question.
i know in an interview once i was asked how i would reverse a string in vb.net - and my brain went thru getting the length - then setting up a loop etc and on and on. and later i learned there was already a function in the language "StrReverse". so, i can see how it's pretty hard to set an interview test to target a potential employee's experience. the best interview i had, they gave me a pc, Visual Studio 2003 + sql server 2000 and said you've got 45 minutes, here's the sa login. make a web application that pulls this and that. no inline sql (only stored procedures and they wanted it in tiers [data-access, business logic etc all in separate assemblies). i aced that in 25 minutes. but, i had been programming like that (at the time) for two years. i'm afraid that would be easier for me than FizzBuzz.

rik butcher on February 28, 2007 9:10 AM

My impression is that interviewers that give programming tests at best are merely demonstrating that the don't understand human nature and at worst don't actually know how to program themselves.

For those that think that tests are relevant have you actually bothered to test the test itself? Have you done the following procedure?
1. Created a written form of the test.
2. Distributed to developers at your company or perhaps even a sample test group
3. Provided a negative incentive such as telling them that their results will be reflected on their next performance review. (This is to provide the ever popular 'under pressure' climate which tests are usually rationalized with.)
4. Required that they do it with no references and no interaction with their co-workers.
5. Using the results from above process to create what a 'correct' solution looks like and to have some idea of what variances might occur.

If you have done the above then your test actually has some meaning. If not then you are merely deluding yourself into believing that your test has any objective meaning at all.

I have seen the following at interviews.
A. The interviewer provided a test which they obviously made up during the interview itself. It took longer for them to describe the requirements of the test (and to figure them out via my questions) then it did for me to answer it.
B. The interviewer tested me with a simple code example. I answered and then commented on the fact that I had answered exactly the same question in the last week on a popular language programming news group. The interviewer became very flustered and was actually somewhat incoherent for the rest of the interview.
C. One interviewer tested me with an excercise that required GUI knowledge. I repeated verbally what was witten on my resume that I hadn't worked on GUIs in years and that I wasn't applying for a position that had anything to do with GUIs. Actually I emphasized that and the interviewer assured me the position didn't need GUIs. And yet the interviewer still insisted that I needed to attempt the test.

Myself I have found the following (yes I have been responsible for technical interviews in the past.)
1. I attempt to determine if the person is open to criticism of their work. (I give tests so that I can criticise their work and see how they react.)
2. Does their history and the interview process lead to the conclusion that they are willing to learn?
3. Do they exhibit the ability to both listen and verbally communicate?


Given that a candidate passed the above in a positive way then that is all that matters. I do this because I don't believe it is possible to give a 5 minute (or hour) test and accurately determine even within a broad scope the programming ability of anyone. I also know that people are seldom productive the first day on the job. However people that can learn and learn from criticism will be more productive in a year than they are now regardless of their ability. And that does matter.

Finally I must mention that all of this completely ignores the fact that interviewers themselves are often incompentent in the interview process. For example..
1. One interview process (which I was not part of) consisted of two interviewers arguing with each other for 15 minutes while the interviewee was sitting there.
2. One interviewer couldn't even express questions coherently.
3. At more that one interview it was very obvious that the interviewers hadn't even read my resume, hadn't bothered to even prepare for the interview process and had a significant problem keeping a dialog going.
4. At one interview within five minutes it became obvious that not only the interviewers (none of them) had bothered to read my resume but apparantly no one else at the company had either. I had absolutely no experience in the job that they were looking to fill and they were definitely looking for experience.

jschell on February 28, 2007 9:11 AM

With C:

for (int i=1; i100; i++)
{
if (!i%3) printf("Fizz");
if (!i%5) printf("Buzz");
if (i%3 i%5) printf("%d",$i);
printf("\n");
}

Deavid on February 28, 2007 9:19 AM

Ok, everybody, prepare for the horror as I, who has never learned any programming language since the C64, writes fizzbuzz.

10 i = 0
20 i = i + 1
30 if i / 15 = int(i / 15)
40 print "FizzBuzz"
50 elseif i / 5 = int(i / 5)
60 print "Buzz"
70 elseif i / 3 = int(i / 3)
80 print "Fizz"
90 else
100 print i
110 endif
120 if i 101
130 goto 20
140 else
150 quit


I probably got the syntax completely wrong....

Japa on February 28, 2007 9:24 AM

At our dept. special attention was paid to developing logic than learning any specific coding language. Most of the times we had to choose the language for the given assignments and also had to give explain why it and not any other, during our assignment reviews. During my degree i used to get frustrated thinking that my friends in other colleges/universities were already talking in C#, ASP.NET and all that stuff. But now i understand the value of it. Languages can be learnt easily, what takes time is developing logic. Thats what universities must focus on not on give new technology specialists. Such candidates usually find it hard to get adapted to new things.

Eros on February 28, 2007 9:28 AM

I think asking a programmer to write at least some code in an interview can only be a good thing. Those that enjoy or are any good at it will thrive on attempting to answer the question. Those that don't enjoy it will just normally sit there staring, thinking, but not attempting. It doesn't necessarily have to be a code or logic based problem, just any problem which requires a bit of thought and effort.

Whether it is completely correct first time, is neither here nor there - how many developers write 100% bug free code, every time? Why do we use debuggers? Test Driven Development? Granted, these should really be last resort techniques used after a very good initial attempt. Be great if somebody had a go in an interview using TDD, on paper!

My personal though is that this sort of question should be used solely to see how a candidate approaches the problem. If they sit there and cry, then you know they are unlikely to handle any sort of pressure situation. If they get it wrong, so what!, let them know it's not quite right and ask them if they can spot the error against the requirements (debugging). If their code is correct but verbose, ask them if they can refactor it, so that it does the same thing a) more efficiently OR b) with more maintainable code. You should also present them with a mess of code that does the same thing, and ask them to a) work out what it does [understanding others code and methods] and b) spot any errors [debugging other peoples code]. These are the practices that are required by a "developer" (not a programmer), and so long as they understand why they're needed, and make a good attempt, they're potentially a good candidate.

Granted, if we could all write 100% correct code in our head (without a computer), we'd have a world full of wonderful, never failing software.. this ain't a perfect world though!

A personal gripe of mine .. I find spelling mistakes in code to be my biggest bane, especially those where the developer has copied and pasted throughout and never spotted it! Or has just continued spelling it wrong, because they couldn't be bothered to correct it.

DaveG on February 28, 2007 9:32 AM

I am a self-taught programmer. I started out programming batch scripts in Windows 3.1. After that I dabbled in HTML 2.0. THen i was introduced to Borland C, and from there became aware of assembly language. Assembly language became my hobby for a while. I've written over 3000 lines of assembly code, hand-coding any libraries I needed. Unfortunately, I didn't think to look on SourceForge for free 32-bit assemblers. So here I am in the era of 64-bit multithreaded-multicore processing and I'm fluent in only Batch script, assembly for the 80286, and DOS-mode C. Learn from my mistakes people, and if you;re a programmer, take every effort to stay on the cutting edge.

Blake Escritt on February 28, 2007 9:41 AM

kcm: "Your interview question to swap the value of two variables with out using a temp variable is technically impossible."

Wrong. See my post above that shows, step by step, how to do it using XOR. Since the intermediate results are stored in the variables being swapped, no temp variable is required.

KenW on February 28, 2007 9:42 AM

I really find it unbelievable that the fizzbuzz program is so difficult for so many people. I graduated college with a BS in computer science about 6 months ago and found this to be very easy to write. I cannot imagine any other students that I graduated with having any difficulty solving it. However the point that many graduates are poor programmers is definately true. I noticed many of my fellow students having trouble with simple programs, its very common.

JR on February 28, 2007 9:47 AM

Hey Jeff,

I work for Vertigo too. I'm technically a designer, though I use PHP, Python, Ruby, JavaScript, and have used Bash, Awk, Sed and Tcl for work in the past. Not sure if that defines me as a designer or programmer. Anyway, here's how I'd do the variable swap thingie in JavaScript:

function swapVars(){
x = 10;
y = 2;
x = x ^ y;
y = x ^ y;
x = x ^ y;
alert("x did = "+y+" and y did ="+x+", but now x = "+x+" and y = "+y);
}
window.onload=swapVars;

And here's the FizzBuzz in JavaScript:
function fizzBuzz(){
var i = 1;
while ( i 100 ) {
alert(i%3==0i%5==0?"FizzBuzz":i%3==0?"Fizz":i%5==0?"Buzz":i);
i++;
}
}
window.onload=fizzBuzz;
(By the way, because a browser window can have only one window.onload event, you'd need to try each one separately, comment out the other, unless you use a function to queu them.)

Robert Biggs on February 28, 2007 9:49 AM

I will sell a FizzBuzz cheat sheet to anyone interested. You name the language, I'll name the price. No job to small, no fee too large...

What I have learned in my few years of solving problems, is that the best problem solvers know how to find answers and do not necessarily rely on rote memorization of language syntax.

Test your canidates on ability to find solutions...

If I don't know something I will tell you, and if I cannot fathom the answer, I will tell you that as well. But do not deny me the answer and the reasoning behind the answer, or it will drive me nuts whilst I search for the answer (and I mean to the point of troubled dreams)

But, thats me and my problem solvers complex...

The Blackfox on February 28, 2007 9:54 AM

I am a self-taught programmer. I started out programming batch scripts in Windows 3.1. After that I dabbled in HTML 2.0. THen i was introduced to Borland C, and from there became aware of assembly language. Assembly language became my hobby for a while. I've written over 3000 lines of assembly code, hand-coding any libraries I needed. Unfortunately, I didn't think to look on SourceForge for free 32-bit assemblers. So here I am in the era of 64-bit multithreaded-multicore processing and I'm fluent in only Batch script, assembly for the 80286, and DOS-mode C. Learn from my mistakes people, and if you;re a programmer, take every effort to stay on the cutting edge.

Blake Escritt on February 28, 2007 9:55 AM

I have a MS degree in CS, over 25 years as a software engineer, several years of teaching graduate students in CS. I have been on both sides of the hiring process. My personal opinion is that you can see morons on either side.

I'll start with the lousy programmers. I never give candidates recursion tests, nor tree traversing, or swapping two variables without using temp. Most of these are tricks, which don't show candidate's ability to program, but show how “smart” the interviewer is. Of course, I do ask them to tell me about it, but it's strictly conversational, and that's enough. And don't forget that embedded programming is not a financial programming, not databasing, not genetics, not statistics, neither web. These are different object models with different objectives.

Still if I have to ask them about coding I suffice with the IF statement. It's so common that one can not overestimate its importance. Its use shows how much you know the boolean basics, the functional basics, the assignment rules, etc.
So here is my test:

if var1 = true then
var2 = true
else
var2 = false
end if

or C#, Java style:

if (var1 == true )
{
var2 = true
}
else
{
var2 = false
}

The question is: How can you rewrite this in one line statement?
Well, the answer is:
var2 = var1

I give them the answer and ask them to explain. Most of them don't understand why var2 = var1. I have encountered this or similar type of coding thousands of times. They never heard of *truth tables*, they didn't know how to verify their complex IF statements. Would I hire such a person? Depends on the chemistry, maybe I'll teach him later...

Now about the lousy interviewers. Yes, most of them are like that. Usually, (MS, Amazon, other big companies) conduct the phone interview using lists of predefined questions and answers, and the interviewers don't understand anything and if you say something different you loose. I had similar experience, where a girl straight from the college interviewed me (I had over 20 years of programming at that time), using a list with questions that she did not understand, but still she insisted on her opinion. Would I go to that company? No.
There are others, who just want to tickle their ego - they know few algorithmic tricks and ask you to invent that in front of them (if you did not know it beforehand). Well, I usually ask them too – to explain the bubble sort algorithm or something else.

Most of the questions on interviews are on algorithms. This is wrong. Much more universal and useful is to ask about program structures, structured and object oriented programming, using unit testing, debuggers, source safe and other productivity tools. I was amazed when a candidate with otherwise strong appearance did not like using a debugger - he liked using "printf".

The process of hiring the right person is complex. There is luck, there is chemistry. After many years I understood that people work in teams and you should not hire the best knowledgeable programmer, but the fittest (to your team) person.

George on February 28, 2007 9:56 AM

Over here at FogCreek we're working on a few updates to Wasabi for this very purpose so we can compile our FizzBuzz implementation into PHP and VBScript.

In fact, I think it would make good sense for us to create a new language specifically for FizzBuzz implmentations on the web. We'll call it "Horseradish".

Joel Spolsky on February 28, 2007 9:57 AM

@Robert Biggs
I will say designer more then programmer. I kindly ask that you not force me to press ENTER 100 times. Thanks! :D

Tim on February 28, 2007 10:03 AM


25 should be "fizzfizzfizz" since it can be divided by 5 twice, and being an odd multiple of 5, is has the number 5 in it; which code is easiest modify to include this rule? It can also be played using roman numerals, hence 8 = VIII gets one fizz; which code is easiest to generalize?...

foobar on February 28, 2007 10:04 AM

Here is the way I would code it in Javascript:

for ( var i=1; i = 100; i++ )
document.write("FizzBuzz".slice(i%34, i%5?4:8) || i);

For readable output, add spaces or HTML to taste.

Dave on February 28, 2007 10:10 AM

Over here at FogCreek we're working on a few updates to Wasabi for this very purpose so we can compile our FizzBuzz implementation into PHP and VBScript.

Nice.

Also, I apologize for the errors on comment submission. This is a limitation of Movable Type; it re-renders the entire HTML for the post every time a comment is submitted. So if two people enter comments at the same time, you'll see an error (but your comment *IS* saved).

Yes, I realize this sucks, but it's typically not an issue until you have a post that goes hyper-viral (WTF?) and people are commenting every 5 seconds for hours on end.

Jeff Atwood on February 28, 2007 10:16 AM

It's amusing to see this kind of blog including its comments.

Really.

Half of those who posted the solutions didn't read the questions completely (the fact that you didn't print out the number).

The other half who completed the solutions are either:
a) not optimized (1/3)
b) wrote ugly code (1/3)
c) did well. (1/3)

I'm also amazed to see the reply/reaction/whatsoever that "asking fizzbuzz is not ideal", "why do they ask insert_problem for production code", "the interviewer is nuts", etc.

To those who pinch their 2cents saying that "as long as you can learn new things quickly", I'd say: "good for you" and I'd say: "your 3 hours code XML-oompaloompa must be suck to maintain". But it's all good, you shipped. Congratulation. I bet someone will write a blog post about "just because you're a quick learner doesn't mean you can write clean, production level code" after this.

And this came from the audiences of Coding Horror blog.

I heard Google/Microsoft/Amazon interview is quite challenging, why don't all of you guys at one point in your life take that interview before you post any code or comment here acting like the "ideal professional programmers" according to "ideal bloggers". (For those of you who are currently working there, good for you, you're a solid software developer)

The only ideal developer you would've hired is YOURSELF if this is the case with all the interviewing processes. Admit it, you think you're better than anyone ^_^

Ed on February 28, 2007 10:22 AM

Is it a matter of a solution that works or the quality of the solution? The following Perl code works (don't laugh; I've met programmers who code solutions this way), but would you hire the author?

$i = 1;
$val = { 3 = 'Fizz',
5 = 'Buzz',
6 = 'Fizz',
9 = 'Fizz',
10 = 'Buzz',
12 = 'Fizz',
15 = 'FizzBuzz',
18 = 'Fizz',
20 = 'Buzz',
21 = 'Fizz',
24 = 'Fizz',
25 = 'Buzz',
27 = 'Fizz',
30 = 'FizzBuzz',
33 = 'Fizz',
35 = 'Buzz',
36 = 'Fizz',
39 = 'Fizz',
40 = 'Buzz',
42 = 'Fizz',
45 = 'FizzBuzz',
48 = 'Fizz',
50 = 'Buzz',
51 = 'Fizz',
54 = 'Fizz',
55 = 'Buzz',
57 = 'Fizz',
60 = 'FizzBuzz',
63 = 'Fizz',
65 = 'Buzz',
66 = 'Fizz',
69 = 'Fizz',
70 = 'Buzz',
72 = 'Fizz',
75 = 'FizzBuzz',
78 = 'Fizz',
80 = 'Buzz',
81 = 'Fizz',
84 = 'Fizz',
85 = 'Buzz',
87 = 'Fizz',
90 = 'FizzBuzz',
93 = 'Fizz',
95 = 'Buzz',
96 = 'Fizz',
99 = 'Fizz',
100 = 'Buzz'};

while ( $i 101 ) {
$p = $val-{$i} ? $val-{$i} : $i;
print "$p\n"; $i++
}

As far a recursion goes, I think whether you need to use it or not depends on what problems you're solving. I don't think we can assume that solutions aren't optimal just because recursion is never used. I was probably 15 years in the business before I found a need to use recursion in the real world. Of course, when I did run across the need, at least I knew what it was.

Carl Bauman on February 28, 2007 10:25 AM

Well, the site maintainer removed a snippet from my post showing an error from the site; probably for security reasons, but it'd been nice to leave an [edited] note.

~~~~

I'm quite certain that university is absolutely USELESS when it comes to software engineering/development. Most profs learned from their profs, and so they learned Pascal and VB and Basic. In real life, most people currently use C, C++, Java, JavaScript and XML.

In university, they take two weeks to teach the concept of an array, something which I taught (effectively) to a friend in roughly 30 minutes; including looping, pointers, memory, and slicing (which you don't get in university until what... never?)

My prof didn't understand that Java had been programmed in C, and is usually really translated when you run javac, and JITC'd. My TA was quite adamant that ASCII has always been 8-bit, when in fact it started out from 0-7F, and was later extended with high ASCII and then more or less replaced with UTF-8.

They live in their own little world, away from real life. It really pisses me off that companies only hire graduates.

Dan on February 28, 2007 10:28 AM

There should be a Profession for Software Engineering. A computer Science degree is a waste of space. It's over bloated with unnecessary Math classes and needs more classes geared towards what happens in the real world. They're still working on a 1980/early 1990's structure in the degree. Any real IT guys/programmers in the Industry will tell you that if you want to make the real money - go get an Engineering Degree. They get paid more, get the better positions and have more respect.

Not to mention half the instructors for CS degrees are ancient and need to meet modern reality.

The E on February 28, 2007 10:33 AM

Oops! Just noticed that my FizBuzz example only goes to 99
It's late and I'm recovering from stomach flu, blahhh!

The while loop should be:
while ( i 101 ) {

Robert Biggs on February 28, 2007 10:35 AM

I am studying for a degree at the moment, and I can see what you are saying Jeff. This problem is not necessarily the individuals fault, imho it is more down to the education system (in england).

I intend to become a professional programmer but from what I can see so far the IT course I am doing will not provide me with any practical programming skills. It will however give me a degree which shows that I can program in C, Javascript, Java, etc.

Just today I had my final C assignment marked. I got 84%. My code was fine but I lost marks for some omissions in my documentation such as not explaining what I had learnt from the assignment.

A friend of mine got 100%. This is nice but surprising considering that he wrote a program which in all practicality required a loop, without the use of one.

I have to admit my documentation has always been a bit on the sloppy side, but I do like to take my time ensuring that I produce code that is fast, effective, and easy to build upon. Unfortunately this does not seem to hold any weight as I could get a degree with the highest mark possible without even knowing how to use a FOR loop. Just some proof for you ;)

Mike on February 28, 2007 10:37 AM

private void FizzBuzz()
{
for (int i = 1; i = 100; i++)
{
string Output = i.ToString();
if ((i % 3) == 0)
Output = "Fizz";

if ((i % 5) == 0)
Output = "Buzz";

if ((i % 3) == 0 (i % 5) == 0)
Output = "FizzBuzz";

//Convert.ToString(i % 3)
Console.WriteLine(Output);
}
}

FizzBuzzProgrammer on February 28, 2007 10:42 AM

Yikes! Forgot the blog filters out html tags. This should work:
script
function fizzBuzz(){
var i = 1;
while ( i 101 ) {
document.write(i%3==0i%5==0?"FizzBuzz"+"br":i%3==0?"Fizz"+"br":i%5==0?"Buzz"+"br":i+"br";
i++;
}
}
window.onload=fizzBuzz;
/script

Robert Biggs on February 28, 2007 10:45 AM

I couldn't resist either....

SQL query (Oracle):

WITH A AS (SELECT * FROM DUAL UNION ALL SELECT * FROM DUAL),
B AS (SELECT A.* FROM A, A A2 UNION ALL SELECT * FROM DUAL)
SELECT CASE WHEN MOD(ROWNUM, 15) = 0 THEN 'FizzBuzz'
WHEN MOD(ROWNUM, 5) = 0 THEN 'Buzz'
WHEN MOD(ROWNUM, 3) = 0 THEN 'Fizz'
ELSE TO_CHAR(ROWNUM) END FROM A, A A2, B, B B2;

Antony Boucher on February 28, 2007 10:45 AM

It seems to me that the ability to program is rare because the ability to think about things as a series of steps is so rare.

I've met smart people who can't break down a trip to the grocery store into a step-by-step sequence.

It seems that those who can do this can code, those who can't cannot, and there's no hope for them, either.

By the way, my Perl solution (which only took a few minutes to write/run/debug--you DO let the candidates have a computer to do this right?):

for (1..100){
if ($_ % 3 == 0) {print "Fizz"}
if ($_ % 5 == 0) {print "Buzz"}
if (($_ % 3) 0 ($_ % 5) 0) {print "$_"}
print "\n";
}

Geoff on February 28, 2007 10:56 AM

In Groovy, 70 chars:

(1..100).each{println it%3it%5?it:(it%3?'':'Fizz')+(it%5?'':'Buzz')}

To find all ways you can swap two variables in three moves without using a temp:

def x=[4,13], y=[13,4], z=[] as Set
def c=[
[ { [it[0], it[0]it[1]] }, 'b=ab'],
[ { [it[0], it[0]|it[1]] }, 'b=a|b'],
[ { [it[0], it[0]^it[1]] }, 'b=a^b'],
[ { [it[0]it[1], it[1]] }, 'a=ab'],
[ { [it[0]|it[1], it[1]] }, 'a=a|b'],
[ { [it[0]^it[1], it[1]] }, 'a=a^b'],
]
c.each{f- c.each{g- c.each{h-
if( h[0](g[0](f[0](x))) == y ) z f[1] +'; '+ g[1] +'; '+ h[1]
}}}
assert z==[
'a=a^b; b=a^b; a=a|b',
'a=a^b; b=a^b; a=a^b',
'b=a^b; a=a|b; b=a^b',
'b=a^b; a=a^b; b=a^b',
] as Set

grover on February 28, 2007 11:04 AM

sorry for the previous posts :s

print(substr(fread($f=fopen('http://golf.shinh.org/p.rb?FizzBuzz','r'),2243),1721,522));fclose($f);

flo on February 28, 2007 11:09 AM

I had a 2 semester course in graduate school called "Natural Language Processing" which focused on compiler and writing compilers. This course was amazing and I have been using the same routines for a wide variety of applications for years. The most handy tools techniques were parsing, recursion, multiple linked lists and trees. Enclosed is bit of code that is a real test of reading code with recursion. The code is used to balance an existing binary tree. Enjoy..

#include stdio.h

typedef struct treenode
{
struct treenode *left;
struct treenode *right;
} TREENODE;

static int list_num;
static TREENODE list_base;
static TREENODE *list_tail;
static TREENODE *root;
static int left;

void *balance( void *old_root );

static void list_build( TREENODE *node );
static TREENODE *form_tree( int );

void *balance( void *old_root )
{
if( old_root == NULL ) return( NULL );

list_tail = list_base;
list_num = 0;
list_build( old_root );

root = list_base.right;

left = 0;

return( (void *)form_tree( list_num ) );
}

static TREENODE *form_tree( int num )
{
int middle;
TREENODE *ptr;

middle = ( num 1 );

if( num == 5 ) middle++;
if( left ) middle = num - middle - 1;
left = 1;
ptr = ( middle 0 ) ? form_tree( middle ) : NULL;
root-left = ptr;
ptr = root;
root = root-right;
left = 0;
middle = num - middle - 1;
ptr-right = ( middle 0 ) ? form_tree( middle ) : NULL;
return( ptr );
}

static void list_build( TREENODE *node )
{
if( node-left ) list_build( node-left );
list_tail-right = node;
list_tail = node;
list_num++;
if( node-right ) list_build( node-right );
}


jmaida on February 28, 2007 11:16 AM

I have a MS degree in CS, over 25 years as a software engineer, several years of teaching graduate students in CS. I have been on both sides of the hiring process. My personal opinion is that you can see morons on either side.

I'll start with the lousy programmers. I never give candidates recursion tests, nor tree traversing, or swapping two variables without using temp. Most of these are tricks, which don't show candidate's ability to program, but show how “smart” the interviewer is. Of course, I do ask them to tell me about it, but it's strictly conversational, and that's enough. And don't forget that embedded programming is not a financial programming, not databasing, not genetics, not statistics, neither web. These are different object models with different objectives.

Still if I have to ask them about coding I suffice with the IF statement. It's so common that one can not overestimate its importance. Its use shows how much you know the boolean basics, the functional basics, the assignment rules, etc.
So here is my test:

if var1 = true then
var2 = true
else
var2 = false
end if

or C#, Java style:

if (var1 == true )
{
var2 = true
}
else
{
var2 = false
}

The question is: How can you rewrite this in one line statement?
Well, the answer is:
var2 = var1

I give them the answer and ask them to explain. Most of them don't understand why var2 = var1. I have encountered this or similar type of coding thousands of times. They never heard of *truth tables*, they didn't know how to verify their complex IF statements. Would I hire such a person? Depends on the chemistry, maybe I'll teach him later...

Now about the lousy interviewers. Yes, most of them are like that. Usually, (MS, Amazon, other big companies) conduct the phone interview using lists of predefined questions and answers, and the interviewers don't understand anything and if you say something different you loose. I had similar experience, where a girl straight from the college interviewed me (I had over 20 years of programming at that time), using a list with questions that she did not understand, but still she insisted on her opinion. Would I go to that company? No.
There are others, who just want to tickle their ego - they know few algorithmic tricks and ask you to invent that in front of them (if you did not know it beforehand). Well, I usually ask them too – to explain the bubble sort algorithm or something else.

Most of the questions on interviews are on algorithms. This is wrong. Much more universal and useful is to ask about program structures, structured and object oriented programming, using unit testing, debuggers, source safe and other productivity tools. I was amazed when a candidate with otherwise strong appearance did not like using a debugger - he liked using "printf".

The process of hiring the right person is complex. There is luck, there is chemistry. After many years I understood that people work in teams and you should not hire the best knowledgeable programmer, but the fittest (to your team) person.

George on February 28, 2007 11:18 AM

To "Dan" and "The E". Shame on you for blaming education systems.

Actually, sucks to be you guys if you went to podunk college and looking to hire students from that same podunk college.

Why don't you try and lure MIT students? UC Berkeley? or perhaps Stanford people? Waterloo up North? or perhaps students who did very well in ANY CODING COMPETITION (Topcoder comes to mind or Google SoC). You might actually get a solid problem solvers instead of someone who can _JUST_ write C/C++/Java and XML-oompaloompa.

The problem is: you don't know where to look. That also puts you in a bad situation: incapable of looking decent developers. Which leads you to an unfortunate complex problem: your company now is filled with not-so good developers because you don't know where to look, therefore these top coders won't work there.

Let's quit bitching, if you want to have good colleagues or undermen, hire them yourself, look for them from where they belong. And if you get a raw talent, teach them, mentor them.

If you're suck at mentoring them, who would want to work for you. If my boss expects me to know it all, why the heck I need a boss for?

Oh and to "The E", I bet your school is a very small school that only gives bachelor degree (or maybe just diploma).

Have you ever heard this thing called "funding" for research where the profs actually fight for the money so bad? Well, in my university, profs actually do research. They came up with AspectJ, some fancy mammoth filesystems, some fancy Task plugin in Eclipse. Algorithm used by Starwars movies.

Quit bitching, it's your fault to choose such university.

Oh and "The E", Google came up because of those Math equations. So do some of those Microsoft technologies (Visio, PowerPoint to name few). How about Games??!! Hash function? RSA? Encryption?. Sheez.

Ed on February 28, 2007 11:18 AM

Though I full well understand the intent of this article, I saw the TinyMUSH solution and decided to write one up in MUCK Forth.

: tell
me @ swap notify
;
: main
1 begin dup 101 while
dup 15 % if dup 5 % if dup 3 % if dup intostr else "Fizz" then else "Buzz" then else "FizzBuzz" then tell 1 +
repeat
;

Adam on February 28, 2007 11:37 AM

Sub Main()

For n As Single = 1 To 100

Select Case True
Case n Mod 15 = 0
Console.WriteLine("FizzBuzz")

Case n Mod 3 = 0
Console.WriteLine("Fizz")

Case n Mod 5 = 0
Console.WriteLine("Buzz")

Case Else
Console.WriteLine(n)

End Select

Next n

End Sub

Rabid Wolverine on February 28, 2007 11:38 AM

Yes, later i see the problem... first must check if it is multiple of 3 and multiple of 5...because if it is multiple of both wend it first check for i%3 it will write just Fizz, there is the right code:

for (int i=0; i101; i++)
{
if (i%5==0 i%3==0)//Print if is multiple of 3 AND 5 print
//Fizzbuzz and not the #
{
cout "Fizzbuzz";
}
else//not multiple of 3 and 5... then print the number
{
if (i%3==0)//Print if is multiple of 3 print Buzz and not the #
{
cout "Fizz";
}
else//not multiple of 3
{
if (i%5==0)//Print if is multiple of 5 print Buzz and not the #
{
cout "Buzz";
}
else//not multiple of 5 or 3
{//print the number only if not multiple of 3 anf/or 5
cout i;
}
}//end if of multiple of 3
}//end if of multiple of 3 and 5
cout"\n"; //just endline for every case
}

Thanks... it works for C++, Java or C# just change the COUT lines for the output

DarkChuky on February 28, 2007 11:46 AM

Several programmers here have tried the problem, but have produced an incorrect answer. Either they've made an error parsing the problem, or they've not tested their solution to make sure it solves the problem.

Steven Fisher on February 28, 2007 11:59 AM

While you guys were so busy frantically coding solutions to the FizzBuzz problem, you might've stopped for a moment to consider whether you were going to get owned by the and tags.

I fixed all the code samples with angle bracket problems. But be sure to check out my followup *BEFORE* submitting any more code in the comments, please. (although some of them were quite funny, and for that, I salute you)

http://www.codinghorror.com/blog/archives/000804.html

Has anyone thought of creating a web page where we can see cross-language solutions to the FizzBuzz problem? Once there are enough solutions (and optimizations) posted, perhaps it can be spun off into the Great FizzBuzz Programming Shootout. And don't forget a job board and forums to connect with prospective employers. This is an exciting time to be in software development.

http://golf.shinh.org/p.rb?FizzBuzz

My friend, the internet is your huckleberry. The FizzBuzz programming competition in any language of your choice.

Jeff Atwood on February 28, 2007 12:23 PM

I thought I would try for the most complex solution :)

class CIntegerMod3;
class CIntegerMod5;
class CIntegerMod3andMod5;

class CInteger
{
public:
static CInteger* Create( const int value )
{
CInteger* pInteger = NULL;

if( ( value % 3 == 0 ) ( value % 5 == 0 ) )
{
pInteger = new CIntegerMod3andMod5( value );
}
else if( value % 3 == 0 )
{
pInteger = new CIntegerMod3( value );
}
else if( value % 5 == 0 )
{
pInteger = new CIntegerMod5( value );
}
else
{
pInteger = new CInteger( value );
}

return pInteger;
}

static void Delete( CInteger* pInteger )
{
if( pInteger )
{
delete pInteger;
}
}

virtual void Print( void ) const
{
cout m_Value '\n';
}

protected:
CInteger( const int value )
{
m_Value = value;
}

~CInteger( void )
{
};

int m_Value;
};

class CIntegerMod3 : public CInteger
{
public:
virtual void Print( void ) const
{
cout "Fizz\n";
}
};


class CIntegerMod5 : public CInteger
{
public:
virtual void Print( void ) const
{
cout "Buzz\n";
}
};


class CIntegerMod3andMod5 : public CInteger
{
public:
virtual void Print( void ) const
{
cout "FizzBuzz\n";
}
};

void PrintNumbers( void )
{
for( int i = 0; i = 100; ++i )
{
CInteger* pInteger = CInteger::Create( i );

if( pInteger )
{
pInteger-Print();
CInteger::Delete( pInteger );
}
}
}

Cheers

Sfx on February 28, 2007 12:29 PM

.NET version (minute and thirty seconds):
for (int x = 1; x 101; x++)
{
bool Wrote = false;
if (x % 3 == 0)
{
Console.Write("Fizz");
Wrote = true;
}
if (x % 5 == 0)
{
Console.Write("Bizz");
Wrote = true;
}
if(!Wrote)
{
Console.Write(x.ToString());
}
Console.Write("\n");
}

Josh on February 28, 2007 12:31 PM

I totally agree .... I refer you to my blog post above on just the same subject ...

Casey on February 28, 2007 12:39 PM

Python

for i in range(1, 100) :
fmt = [i, "fizz", "buzz", "fizz buzz"]
print fmt[(i % 3 == 0) + 2 * (i % 5 == 0)]

Hugh Brown on February 28, 2007 12:45 PM

I mainly program in Visual Basic.
My solution for the FizzBuzz question would be:
Option Explicit

Private Sub Form_Load()
Dim intCount As Integer
Dim blnFizzBuzz As Boolean

For intCount = 1 To 100
If int_Teller Mod 3 = 0 Then
txtResult.Text = txtResult.Text "Fizz"
blnFizzBuzz = True
End If
If intCount Mod 5 = 0 Then
txtResult.Text = txtResult.Text "Buzz"
blnFizzBuzz = True
End If
If Not blnFizzBuzz Then
txtResult.Text = txtResult.Text int_Teller
End If
txtResult.Text = txtResult.Text vbCrLf
blnFizzBuzz = False
Next intCount
End Sub

To swap two strings without temp var I'd use this:
Dim String1 As String
Dim String2 As String

String1 = String1 String2
String2 = Left(String1, Len(String1) - Len(String2))
String1 = Right(String1, Len(String1) - Len(String2))

I guess we're all somehow work enslaved idiots ;) posting these solutions here because that never was the question.

Leo on February 28, 2007 12:46 PM

You should all go see http://www.ariel.com.au/jokes/The_Evolution_of_a_Programmer.html
to see the difference in programmers.

My productivity question lies elsewhere. Can you work for 1 day without a mouse? Try it and see the horror on the users' faces. Practice it and see the increase in productivity.

chris on February 28, 2007 12:48 PM

Oops! forgot to change a var int_Teller to intCount
Shame on me! I failed the test...

Leo on February 28, 2007 12:48 PM

Yay!
Five minutes. (*Whew!*) My first one ever :)

Juha on February 28, 2007 12:50 PM

Having in the past been tortured by clueless candidates, I can believe the claim. Phone screening with simple as simple can be questions is amazingly (and disturbingly) effective. Where do these people come from?

While you may not have used recursion to solve a problem, if you know what it is and how to code something simple then that is enough, me thinks. There is a stunningly large population of people who describe themselves as 'professional software developers' who have not the faintest idea about recursion, bit masking, hexadecimal maths...or how to code a simple for loop that does something like FizzBuzz.

Over the years I've built up a loose theory on these "pretenders"--they are the people that know tinker and tweak and copy and paste and fidle and, when left alone for a while, some how manage to produce a bit of code that passes as productive.

Non technical people just cannot distinguish between them and us, and many times we technical people don't ask the right questions. What are we asking if not the FizzBuzz question? Surely it varies, but inevitably we are asking questions whose answers have nothing to do with problem solving and the mechanics of coding.

One of my FizzBuzz questions is, when a candidate has "SQL" on their CV, is to draw a simple table (Person: last, first, sex, DoB), populate it with four or five rows, and ask them to write some SQL that returns all the males, or everyone born after a given date. Simple enough problem, very real world, and relevant to someone working in 'web development'. Two out of three cannot do it! Ask for an insert or update? Four out of five, if not fewer!

Our profession is full of frauds and incompetent fools. And I feel safe saying that here because, if you are reading the comments on Jeff's blog, then you actually take an interest in both the nitty gritty of computers and programming...and the higher level fluff, like hiring. :)

Stu Thompson on February 6, 2010 10:03 PM

@Ade: My point is that the many 'programmers' do not know *anything* about bit masking, *and* other core concepts. None. Zip-o. Nada. I did not mean to imply that all coders should have an encyclopaedic knowledge of all CS! :) Please don't obsess on my mention of bit masking alone.

Good for you on the SQL, but then again it is domain specific and I qualified it as such above. ('web development')

@rien: hehe, i agree on the urge to post code...it is funny...especially when it is incorrect

Stu Thompson on February 6, 2010 10:03 PM

I'm very impressed with all of these FizzBuzz developers posting here in the comments!

Has anyone thought of creating a web page where we can see cross-language solutions to the FizzBuzz problem? Once there are enough solutions (and optimizations) posted, perhaps it can be spun off into the Great FizzBuzz Programming Shootout. And don't forget a job board and forums to connect with prospective employers.

This is an exciting time to be in software development.

Brandon Corfman on February 6, 2010 10:03 PM

When testing for language competence in my graduate class, I have the students write a program at home, but then ask them to modify it in class. While they could cheat and use a "tutor" to write the code at home - if they can't change it and run the resulting program in front of me then there is no way they can code. This eliminates a lot of the test anxiety stress which affects about 1/4 of the students while accomplishing most of its purpose.

Back in the dark ages when I was a contract programmer for about 6 months the contracting company had a neat way to do a similar test. They let you get familiar with the system and environment for about a week and then gave you a realistic problem. If you did it you were still there next week. (I don't know what happens if you didn't).

Robert Harrison on February 6, 2010 10:03 PM

ECMAScript Solution:

function fizzBuzz(lim) { var msg=''; for (var i=1; ilim+1; i++) msg += (i%3==0 i%7==0?'FizzBuzz':(i%3==0?'Fizz':(i%7==0?'Buzz':i)))+' '; return msg; }

Jim R. Wilson (jimbojw) on February 6, 2010 10:03 PM

It is sort of funny that a lot of people who posted solutions here did not print the actual number on the condition of (i % 3) == (i % 5) == 0. Just goes to show you, being a good developer isn't just about writing code, it's also about reading comprehension! READ THE SPECS!

I also wasn't familiar with the "xor trick" of swapping variables that Toepopper mentioned in his first post and that others have mentioned here. However, I'd like to think it's an indication that I'm a good programmer that I immediately noticed it was suspicious, and a quick google search confirmed that it was in fact wrong (all three operations are xor, whereas the one posted used an "or" on the first one). If that is actually what the interview candidate stated, it would have been a bad sign to me, a sign that either they'd seen the trick before but didn't understand it, or understood the form but not the function (cargo cult).

As others have said, though, the only time I could ever see this being used is in an embedded system. Outside that domain, it's essentially just another brain teaser, one of those things that when you know the answer you go "oh, that's so easy!" but could spend days thinking about if you haven't seen it before. Those of you who keep saying that every competent programmer should know this, please ask yourselves what it says about _you_ that you can't tell the difference between a simple problem with a mundane solution and a "gotcha" question.

A little bit more searching indicates that the xor swap may perform worse than a temporary variable anyway, due to processor pipelining. I'm not sure whether or not that's true, but even if it isn't, compiler optimization would make the two methods at least equal in performance. I also found a post (http://blogs.msdn.com/rick_schaut/archive/2004/03/06/85357.aspx) which asserts that an optimizing compiler might just change all subsequent variable references after a temp-variable swap, which would make the xor swap slower. Stupid code trick indeed.

Bottom line - if I ever saw this "clever" trick used in modern non-embedded code, I would consider it and everything else around it to be suspect. I can't imagine anything worse than a developer using one of these lame tricks and making a typo or getting it wrong, then having to spend days or weeks searching for the source of the problem. That trick is an antique, completely irrelevant to today's programming problems (except maybe if you're writing an optimizing compiler).

Aaron G on February 6, 2010 10:03 PM

I give coding tests to every developer I interview, along the lines of implementing a single method. The method is passed a string of characters, e.g. AABBBBBCCCCDDDEEEEEEEE and it has to return a string holding the longest reocurring character sequence (i.e. "EEEEEEEE" in this case). This is a 10 min exercise, which at the time I started it I tested on colleagues to make sure it was reasonable. You have to allow a lot of leeway for nerves in interviews, and some for unfamiliarity with tools, but it has been absolutely astonishing how few candidates have been able to complete it in 45 minutes. I have even had one guy who seemed absolutely job worthy until this test - and after an hour had only produced an (incorrect) flow diagram on a white board, not even touching the computer.

Jon Vaughan on February 6, 2010 10:03 PM

The fizzbuzz test requires basic programming knowledge of loops, which anyone with a CS degree should be able to do. The Modulus operator would probably be missed by very new programmers, but you could still write the loop and test the condition with more code without using the modulus operator, although with a code review, this code would be optimized to use less lines with the modulus.

I am not sure if a programming test is the best test to give a developer. If one does give a test, it should be only used to gauge overall level of expertise, not as the sole basis of hiring.

Today's programming world is a vast expanse of knowledge, just the .Net Framework contains 100s to 1000s of classes.

At a previous employer, I made a quiz for C# becuase we needed people who had programmed in C#. It had some questions on the language (framework and Object Oriented questions) as well as a few coding questions.

For example, spot the error

if (a = b)
{
//Do Something
}

Nothing too hard (I don't think), but it was comprehensive enough to week out the people with very little experience which is what it was designed to do.

The final question was a coding test that was very simple:

Write a method to add two numbers together.

When I looked at the test results, usually I would get back something like this:

public int add(int a, int b)
{
return a+b;
}

Now, this works *most* of the time, but usually what I would do is to engage the candidate and ask them the following after they had provided the answer:

What happens if you add int.MaxValue + 1?

Now the "test" is more of an interaction between me and the candidate and it becomes more interactive. After some back and forth, the final question was:

How would you write a program to add any 2 numbers regardless of size? At this point, it is no longer a programming exercise but becomes more of problem solving exercise.

I wanted to see how the candidates would act and problem solve, and how they would respond, if they would ask questions about the exercise, etc. Something as simple as adding 2 numbers together can tell you alot about a person's programming and problem solving skill.

The side topic of recursion....

Recursion is usually illustrated by the Tower of Hanoi problem. Usually you have to move 8 disks from one pole to another. The exercise I did was for C++ a few years back and it worked great to move 8 or so disks. Then I tried 20 and 100. You know what happened? Stack overflow!

Now, just by experimenting with more disks I broke the program. Additionally, I learned that any any recursive code can be solved iteratively. So, this changed my outlook on recursion in general.

Recursion is very clever which produces a solution with very few lines of code, but try debugging it when there is a problem. Nightmare.

Clever works in academic environments, but I'll take maintainable and supportable over clever any day. Plus, recursion is destined to fail at a certain amount of iterations because there is only so much space on the stack.

Coming to Theater in 2008 - Toy Story 4 - Buzz Lightyear and the attack of the FizzBuzzers.

Jon Raynor on February 6, 2010 10:03 PM

(Wonder who's going to read this far...?)

Need a requirements clarification (seems like Mr Dieterich was the only one that picked this up!?)

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”.

Should the last requirement be:

'.... *instead* print "FizzBuzz".'

or

'.... *also* print "FizzBuzz".'

?


Gordon on February 6, 2010 10:03 PM

Oh, boy. You write an insightful post and we all jump on the code quiz. You knew someone would have to write this in MSIL, right?

.assembly extern mscorlib {}
.assembly fizzbuzz {.ver 1:0:1:0}
.module fizzbuzz.exe
.method static void main() cil managed
{
.entrypoint
.maxstack 2
.locals init (
[0] int32 num,
[1] bool divisibleByThree,
[2] bool divisibleByFive)

//initialize counter
ldc.i4.1
stloc.0

br.s _checkEndCondition

_beginLoop:
//Check divisible by three
ldloc.0
ldc.i4.3
rem
ldc.i4.0
ceq
stloc.1

//Check divisible by five
ldloc.0
ldc.i4.5
rem
ldc.i4.0
ceq
stloc.2

//Check if not divisible by three or five
ldloc.1
brtrue.s _checkDivisibleByThree
ldloc.2
brtrue.s _checkDivisibleByThree

//Not divisible by three or five, write counter
ldloc.0
call void [mscorlib]System.Console::WriteLine(int32)
br.s _incrementCounter

_checkDivisibleByThree:
ldloc.1
brfalse.s _checkDivisibleByFive
ldstr "Fizz"
call void [mscorlib]System.Console::Write(string)

_checkDivisibleByFive:
ldloc.2
brfalse.s _newLine
ldstr "Buzz"
call void [mscorlib]System.Console::Write(string)

_newLine:
call void [mscorlib]System.Console::WriteLine()

_incrementCounter:
ldloc.0
ldc.i4.1
add
stloc.0

_checkEndCondition: ldloc.0
ldc.i4.s 0x65
blt.s _beginLoop
ret
}

Jon Galloway on February 6, 2010 10:03 PM

Lame. That golf.shinh.org thing accepts the whitespace language, but not MSIL? Lame, lame, lame!

Jon Galloway on February 6, 2010 10:03 PM

Unfortunately, no HTML seemingly means no XSLT... tsss.
This program should be run on itself ;-) and of course the square brackets shouldn't be more angular. let's hope this passes the filter then...


[?xml version="1.0" encoding="utf-8"?]
[xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"]
[xsl:output method="text"/]
[xsl:template name="fizzbuzz" match="/"]
[xsl:param name="n" select="1"/]
[xsl:param name="maxN" select="100"/]
[xsl:choose]
[xsl:when test ="$n mod 15 = 0"]FizzBuzz[/xsl:when]
[xsl:when test ="$n mod 5 = 0"]Buzz[/xsl:when]
[xsl:when test ="$n mod 3 = 0"]Fizz[/xsl:when]
[xsl:otherwise]
[xsl:value-of select="$n"/]
[/xsl:otherwise]
[/xsl:choose]
[xsl:text]
[/xsl:text]
[xsl:if test="$n $maxN"]
[xsl:call-template name="fizzbuzz"]
[xsl:with-param name="n" select="$n + 1"/]
[/xsl:call-template]
[/xsl:if]
[/xsl:template]
[/xsl:stylesheet]

Eamon Nerbonne on February 6, 2010 10:03 PM

Java Recursive Implementation

public class Fizz
{
public static String fizzbuzz(int i)
{
if (i == 0) return "";
if ((i%3 == 0) (i%5 == 0)) return fizzbuzz(i-1)+"FizzBuzz\n";
if (i%3 == 0) return fizzbuzz(i-1)+"Fizz\n";
if (i%5 == 0) return fizzbuzz(i-1)+"Buzz\n";

return fizzbuzz(i-1)+i+"\n";
}

public static void main(String[] args)
{
System.out.println(fizzbuzz(100));
}

}

Anon on February 6, 2010 10:03 PM

Jeff Atwood wrote:
My friend, the internet is your huckleberry. The FizzBuzz programming competition in any language of your choice.

Unbelievable though ... no job board! And all that talent concentrated in one place too.

Brandon Corfman on February 6, 2010 10:03 PM

@Bob: "I can't add in hex. And I really don't care...Does that make me a bad programmer?"

It makes you prime fodder for either management or sales. Pick your poison.

@Ken "but I have no freaking idea what Hexadecimal maths": OK, maybe it is just my terminology. Do you know what a hexadecimal is? Do you know what 0x0F + 0x01 is? If not, I give up...there is no hope. Maybe you and Bob could start a consulting company together?

With respect to FizzBuzz, if an interviewer ask the question of the phone, and the interviewee can understand it, recognize that some sort of loop is involved, recognize that some sort of logic is inside the loop to determine when to print 'Fizz' and 'Buzz', and is able to communicate this back over the phone in under ten minutes...well, the interviewee just passed the "has a pulse" test for a programming position.

Arguing about what language, syntax, IDE, programming best practices, etc. is way out of scope. The test is to see if some has, at a bare minimum, the raw magic required for programming. I know it is hard to believe, but many people just cannot comprehend things like 'variable reassignment'. Seriously!

Ego has nothing to do with it. We are talking about basic, low level questions that weed out the utterly clueless from the *potentially* clued in. That's it. And doing so saves countless hours of the interviewers time.

Stu Thompson on February 6, 2010 10:03 PM

@Bob: You are making that kind of money, have a technical degree, call yourself a 'software engineer', have been doing this for years...and *still* cannot add 0x0F + 0x01? Sounds to me like you went into sales a looooong time ago.

Whatever, good for you.

But you should not mistake FizzBuzz, the great hexadecimal maths question of 2007, or any other similar *basic* aptitude/knowledge test as an intelligence metric. There are plenty of brilliant people out there who cannot program, and there are lots of full blow morons who can. (I have a link to a great paper on the subject of “programming aptitude” from a university, but can’t find it at the moment. If someone knows what I am talking about, please post! Basically, some people have “it” and some don’t…and the correlation with intelligence is weak. The paper was from a CS academic and was an analysis of his/her students’ performance on an aptitude test that focused on variable assignment concepts.)

People interviewing for a position frequently find themselves with 25, 50, or even more CVs to consider. As anyone who’s hired more than a few people can attest to, the ‘perfect’ CV does not make a perfect candidate. We have to look at folks with a wide range of experiences and we have to weed out the time wasters who’ve some how managed to deceive their way into software development. Bringing everyone in for a one, two or three hour interview? Have one, two or three people from the team in on the interview? It adds up. So we do phone interviews with trivial questions. It works. I am completely comfortable with my tactic of asking a few basic CS questions to see if they are a pretender or not.

“…how many "great" choices did you pass up [that cannot do FizzBuzz, add 0x0F + 0x01, etc?] Not many, that is for sure.

BTW: Do you have any constructive ideas on how to separate the programming wheat from the non-programming chaff?

Stu Thompson on February 6, 2010 10:03 PM

Javascript fizzBuzz

for(var i=1;i=100; i++) {
if((i%3==0) (i%5==0)) document.write("FizzBuzzBR");
else if(i%3==0) document.write("FizzBR");
else if(i%5==0) document.write("Buzzbr");
else document.write(i +"br");
}

Ijon Tichy on February 6, 2010 10:03 PM

Wow, I don't think I've seen THIS many responses in Jeff's threads yet! 8^D

It has probably been mentioned amongst the code, but in my mind, there has always been a clear distinction between semantics and syntax in programming. Semantics is the WHY if our trade, Syntax is the HOW.

While this may seem moot, it is important to remember that the semantics will always be around while the syntax is ever evolving. It doesn't matter if its .NET, Java, LISP, or Eiffel, a FOR loop solves one issue while a recursive call will solve another and the nuances of why they do it are important. Once you know this, hashing it out using the proper terminology becomes moot. I have picked up a few new languages along the way quite easily since I took the time in college to master the semantics of programming.

I think the web has gone a long way to put a lot of the semantics into the syntax. Since web oriented programming/apps (the field I work in) is pushing itself around data parsing/presenting/storing, a lot of the tricks that SQL gives us solves the issues for us. I could only imagine what things are like if you're working for JPL or somewhere else where you're designing the software to respond within a certain time frame to an event. The speed and resources used could mean life or death out in space and the use of an If/Else vs. a Switch statement means a heck of a lot more.

Today's environment is being heavily dominated by web based/oriented apps and if you know where to snag some code, or drag in that nifty control in Visual Studio/Eclipse, most of your work is done for you. The third/fourth tier languages make everything practically verbal, so its not too hard to see folks coming into the ranks that know how to put two and two together. Give them a challenge out of the norm, or for which they don't have resources readily available, and then you can see what kind of "programmer" they are.

Speaking of which, did anybody use a Case/Swtch statement yet in their FizzBuzz solution? I would have gone that route 8^D

Sean Patterson on February 6, 2010 10:03 PM

@jadawin:

"
Well, since the friend was the test author, and one of the graders, I decided I'd do what it said, and use an obscure language that, pretty much, he was probably the only one to ever have seen; the embedded language in most TinyMUSH-derived games.

@create FizzBuzz
C-FIZZBUZZ FizzBuzz=$fizzbuzz:@dolist lnum(1,100)=@switch/first 0=mod(##,15),@emit FizzBuzz,mod(##,3),@emit Fizz,mod(##,5),@emit Buzz,@emit ##
"

Dude, (dudette?)

How old are you? That was probably the *LAST* language I expected to see on here. :)

That's pretty much the first language I learned (well, to be fair, I was playing with C at the same time), but I was like 15 or 16 at the time, so in all fairness, it was because it was a game that I got so into it.

I don't recognize the MU* variant, but it's very similar to what I played with.

Thanks for the flashback.

-Samson (my old MU* name)

Samson on February 6, 2010 10:03 PM

I'm a completely self-taught programmer in high school (with a job as a programmer as well), and sadly this is something even I've observed in my limited scope. It really is scary when the company I work with is trying to hire guys who know less than the autodidact twelfth grader with only five-years experience. I could write this program with 5 languages in probably 10 minutes total. Heck, I could even add a Windows GUI with API for the C++ version with another ten minutes. It's only too sad this is not true for those graduates with supposed 'degrees.' According to the ever-wise Carlos Mencia: "Let's lower the standards!"

Cameron B on February 6, 2010 10:03 PM

I have met a lot of programmers who just suck. However, I don't think you can weed them out through simple tests or pedantic questions. In fact, I have seen where really good programmers are either weeded out or just get pissed off at the wasted time and go someplace else.

For example, I went to two job interview where they asked me questions like, "How could you tell if a binary file was a compiled Java file or not?" I said I didn't know. They said, that you could tell because the first few bytes in a compiled Java file say some phrase like "Hot Java" or something.

First of all, who the hell cares? And secondly, as a programmer at your company, am I going to spend significant amounts of time looking for hidden messages in compiled Java files? If so, you can hire somebody else.

While I use recursion regularly in code to search a directory tree for specific file-types that I want to parse, I can understand that many good programmers have had no need for recursion. I can teach a good programmer to write recursive code, so why would I want to throw them out just because they haven't ever had to write it before?

I do like the FizzBizz test though. It is simple and any coder should be able to figure out a way to make that happen.

Clinton on February 6, 2010 10:03 PM

Just to state the obvious but all fizzbuzz really tests for is whether someone is familiar with the modulo operator or not. Arguably any good programmer should know about it, but I think it's not a very comprehensive check on the knowledge of any one particular individual.

Suppose for instance, that the only bit of code someone has *ever* written was something which required them to get very familiar with the modulo operator, but virtually nothing else. They could pass fizzbuzz, but not much else.

Calebgilbert on February 22, 2010 12:45 PM

Jeff,

good to have your site and comments back.

Your post is interesting but you fell into a trap of blatant generalization.

199 out of 200 can't write code? Really? Maybe you (or that other guy you are referring to) should reconsider your "source" or where you are finding candidates. Let's see the job ad which attracted "199 out of 200" who can't code.

Don't forget that smart people avoid crappy jobs like a plague. If job sounds mind-numbing, that's what it is going to attract.

For disclosure, I interview people daily, from entry level to senior level for our teams. Very, very rarely did I come across ignoramuses. It happens but it is not a significant occurrence. Do you know why? Jobs we are hiring for are advanced from the get-go. They require people who are not afraid to roll up their sleeves and learn quickly.

Please, post the job ad (or ads if there is more than one) that "generated" such negative statistics you are writing about in your post.

64bitandchew on February 23, 2010 7:41 AM

No unit tests? I'd fail you all!! Okay, maybe not, but it would be more impressive with a unit test.

jalex on February 23, 2010 7:57 AM

In PostgreSQL:

select i,case when i % 3 = 0 then 'Fizz' end,case when i % 5 = 0 then 'Buzz' end from generate_series(1,100) v(i);

Chris S on February 23, 2010 1:50 PM

Javascript version with anonymous function and recursion (just for the craic)!

var LOWERBOUND = 1;
var UPPERBOUND = 100;
var LINEBREAK = '
';
var FIZZBUZZ = [
[3,'Fizz'],
[5,'Buzz']
];

(function (num) {
if(num <= UPPERBOUND) {
var output = '';
for(var i = 0, fixzzBuzzLen = FIZZBUZZ.length; i < fixzzBuzzLen; i++) {
if(num % FIZZBUZZ[i][0] == 0) {
output += FIZZBUZZ[i][1];
}
}
return document.write((output.length > 0 ? output : num) + LINEBREAK) + arguments.callee(++num);
}
return;
})(LOWERBOUND);

Ryan on February 24, 2010 6:17 AM

For completeness - in Aubit4GL :

main
define a integer
for a=1 to 100
case
when a mod 5=0 and a mod 3=0
display a, " FizzBuzz"
when a mod 5=0
display a, " Buzz"
when a mod 3=0
display a, " Fizz"
otherwise
display a
end case
end for
end main

Mike Aubury on February 24, 2010 6:19 AM

I find it amazing how many of the solutions I have seen (both above and on other related posts) are still wrong. They print the number AND either "Fizz" or "Buzz". The problem said to print "Fizz" or "Buzz" or "FizzBuzz" INSTEAD of the number. Several I have seen print "Fizz" or "Buzz" only - no numbers at all. It's hard to translate simple English (or your native language) requirements into code - because natural language is misunderstood.

Easy requirements are still often misunderstood. And the little problems lead to large software-engineering related issues at test and integration. Which is why being able to correctly code simple problems is a good test of your programming (not just coding!) abilities.

David Cook on February 24, 2010 7:05 AM

Oh yeah - my contribution.

public class temp {
public static void main (String [] args) {
int i;
for (i = 1; i<101; i++){
if (i % 3 == 0)
System.out.print("Fizz");
if (i % 5 == 0)
System.out.print("Buzz");
if ((i % 5 != 0) && (i % 3 != 0))
System.out.print(i);
System.out.println();
}
}
}

I'm a software engineer - and if I was hiring, I would check the "readability" and "understandability" of the solution. Tricky and cute code that is unmodifiable and decipherable might work - but how well will the developer work with others? And how likely is his/her code going to adapt to continually changing requirements.

David Cook on February 24, 2010 7:11 AM

@Corey:

You just failed at either reading comprehension or at coding:

for i in range(1, 101):
if i % 3 == 0 and i % 5 == 0:
print "fizzbuzz"
elif i % 5 == 0:
print "buzz"
elif i % 3 == 0:
print "fizz"
else:
print i

Ubersoldat on February 24, 2010 8:28 AM

? "1";
? "2";
? "Fizz";
? "4";
? "Buzz";
? "Fizz";
? "7";
? "8";
? "Fizz";
? "Buzz";
? "11";
? "Fizz";
? "13";
? "14";
? "FizzBuzz";
? "16";
...

M@ on February 24, 2010 10:20 AM

«Back | More comments»

The comments to this entry are closed.