I <3 Steve McConnell*
Coding Horror
programming and human factors
by Jeff Atwood

February 27, 2007

FizzBuzz: the Programmer's Stairway to Heaven

Evidently writing about the FizzBuzz problem on a programming blog results in a nigh-irresistible urge to code up a solution. The comments here, on Digg, and on Reddit-- nearly a thousand in total-- are filled with hastily coded solutions to FizzBuzz. Developers are nothing if not compulsive problem solvers.

It certainly wasn't my intention, but a large portion of the audience interpreted FizzBuzz as a challenge. I suppose it's like walking into Guitar Center and yelling 'most guitarists can't play Stairway to Heaven!'* You might be shooting for a rational discussion of Stairway to Heaven as a way to measure minimum levels of guitar competence.

But what you'll get, instead, is a blazing guitarpocalypse.

Eddie Van Halen's Patent

I'm invoking the Wayne's World rule here: Please, No Stairway to Heaven.

Wayne's World: Stop, No Stairway   Wayne's World: No Stairway Sign

FizzBuzz was presented as the lowest level of comprehension required to illustrate adequacy. There's no glory to be had in writing code that establishes a minimum level of competency. Even if you can write it in five different languages or in under 50 bytes of code.

The whole point of the original article was to think about why we have to ask people to write FizzBuzz. The mechanical part of writing and solving FizzBuzz, however cleverly, is irrelevant. Any programmer who cares enough to read programming blogs is already far beyond such a simple problem. FizzBuzz isn't meant for us. It's the ones we can't reach-- the programmers who don't read anything-- that we're forced to give the FizzBuzz test to.

Good software developers, even the ones who think they are Rockstars, don't play Stairway to Heaven. And instead of writing FizzBuzz code, they should be thinking about ways to prevent us from needing FizzBuzz code in the first place.

* via Jon Galloway and Steven Burch.

Posted by Jeff Atwood    View blog reactions
« Why Can't Programmers.. Program?
Choosing Anti-Anti-Virus Software »
Comments

Is there a term for people who compulsively answer rhetorical questions?

Kenny on February 28, 2007 12:26 AM

Yes there is, isn't there?

Manu on February 28, 2007 12:39 AM

I think you just managed to gracefully hit that button in each of us, that makes us want to prove ourselves.

Nicely done :)

Juha on February 28, 2007 1:06 AM

In the guitar shop where I'm mostly buying stuff nobody is allowed to play "Seven nation army". (or a Nirvana song I've forgot)
All the clerks roll their eyes if anybody starts playing that.

Bernhard on February 28, 2007 1:08 AM

First solution:

http://www.themathlab.com/music/stairway.mid

I win!

James on February 28, 2007 1:15 AM

And yet many of the comments yesterday fell along the lines of "anyone can do that" (no, they can't...and that is the point), "a puzzle like this does not prove anything" (a puzzle??? FizzBuzz is a quick and effective competency test to weed out the losers early on). Cwazy sheep.

A new entry for the Diagnostic and Statistical Manual of Mental Disorders: FBOCD (FizzBuzz Obsessive-Compulsive Disorder)!

Sorry Jeff, my opinion of the average intelligence of the readers of you blog has dived. :( But just a little bit &#61514;

Stu Thompson on February 28, 2007 1:31 AM

using Codinghorror.Blog;

BlogPost post = Blog.LoadBlogPostByID("00781");

foreach (Comment comment in post.GetAllComments())
{
if (comment.Index % 2 == 0)
{
comment.Tag = "Rockstar developer";
}
}


sorry :)

Peter Palludan on February 28, 2007 1:36 AM

This reminds me the temptation of trying so when people read "90% of people can't touch one's elbow with one's tongue."

Kevin Lee on February 28, 2007 1:42 AM

Jeff after this post i really respect you.. really! :D
buuuut i would like to read some articles about java sometime..
i know that properly is not ur field but surely with all your experience, you know alot about it.. at least i think so.
Regards

ps. this post is a little off topic argh

Donnie from Rome on February 28, 2007 1:57 AM

Donnie, here's a good article on Java.

http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html

Siegfried on February 28, 2007 2:22 AM

I stumbled on the FizzBuzz discussion by accident and enjoyed reading all the way to the bottom. I'm at the other end of the employment train (leaving rather than joining). Programming is just a hobby interest for me and I was delighted to see I had got the FizzBuzz sort-of right quite quickly after failing miserably with a series of non-programming trick questions yesterday.

My experience is that the problem identified by Jeff applies in all fields. Most people can do, by rote, what they have been trained to do but have no idea how to do stuff when a broader perspective is required. At an interviewing course years ago the teacher was adamant about asking interviewees "what do you think of that [experience], looking back?". In other words, trying to see if they learned anything, or if they could stand outside their experience and look at the big picture. He also said "hire a learner". [Of course most interviewers haven't a clue :)]

On thing that was not mentioned was the issue of debugging. Maybe the various posters take that skill as a given. In my experience the ability to diagnose problems efficiently is the most elusive of human skills. It is a skill that is required in many walks of life - auto-mechanic, physician as well as programmer. However the ability to debug seems to have a much higher importance in computer programming.

There are lots of clever ways to solve problems in programming. But the choice of solution depends on the context and the specification - neither of which can be adequately explained in a short question. The solutions that simply printed out the answers line by line work, provided there will never be a change in the requirement. The need to swap to things seems to me to be an undesirable level of cleverness that would lead to problems - and some people identified that.

If I was hiring someone to jump in and write code tomorrow it might be more effective to give them a page of code (ideally on laptop) and ask them to fix it - together with explaining their thought process as they were going about the task.

If I was hiring someone who could grow into the task I would be content with a generic answer to the fizzbuzz problem - for example "loop through the numbers and check whether each number is divisible by 3 or 5. Then print the answer depending on that test" That could lead to another question "how would you know if it was divisible by 3?". What I would like to know is whether the person was capable of conceiving a solution to a problem - it is easy to look up the details once you have a suitable plan. Indeed, with Google, programming is probably the "science" in which it is easiest to look up the details.

Another characteristic that is sadly lacking among computer geeks is the ability (or willingness ???) to understand the non-computer client's needs, or to express back to the client his/her need in ways that enable the non-computer person to express the requirement better. I had a sharp experience of this recently where I was never once asked "what are you trying to achieve - maybe there is another solution?". Personally I regularly find myself saying to someone "I don't think I understand your question" - and I find it is better to let them struggle to explain themselves rather than to prompt them in what may be the wrong direction. If I was hiring someone who would interface with clients I would be looking for this skill as well as the ability to program. Getting the specification right solves 80% of the problem.

Finally, an interesting aspect of all the responses was the various languages that people use. I think it is 100% safe to say that they are all less comprehensible to the reader than the initial VBscript example. By comprehensible I mean how quickly could you figure out what the program snippet does after you have forgotten how you did it, or could you figure out what someone else wrote.

Robin2 on February 28, 2007 3:16 AM

Well of course.

I suspect that while there was a rapid digression into solution-space, there was also a perceived need to demonstrate that the responder was, through their ability to code a solution, competent to comment.

Guilty as charged, your honour.

Mike Woodhouse on February 28, 2007 4:09 AM

Thank you! Very reasonable.
And thank you again for sharing this, as you say it's depressing but important.

Sugggan on February 28, 2007 4:09 AM

I suppose the article could be interpreted as a challenge; your recent posts about "some people just don't/won't get it" would no doubt strike fear into the hearts of aspiring developers who worry they might not "get it". Perhaps the solutions are merely a self assurance that they are in the exclusive developer club, only for people who "get it".

Greg Poole on February 28, 2007 4:13 AM

"The mechanical part of writing and solving FizzBuzz, however cleverly, is irrelevant. Any programmer who cares enough to read programming blogs is already far beyond such a simple problem."

I'm sorry, but I disagree. I read about half the comments on the last post and didn't see one genuinely good solution to the problem. None contained a single comment, all utilised hard coded constants and most were just plain obfuscated. I'd expect more from students, let alone graduates and professionals.

I think in an interview I'd hire a programmer who couldn't quite get the problem right (okay maybe not for a problem this simple), but did so in a clear and readable way rather than someone who gets it right but all crammed into a few short unreadable lines.

Pete on February 28, 2007 4:23 AM

Looking at the comments to Phil's post, it turns out some people can't read at all....

Adi on February 28, 2007 4:31 AM

Compulsive puzzle solving is right. Both my wife and I are coders, after reading this I related the results and basically both of us started figuring out other questions of similar weight [after answering the question as quickly as possible first]. Yet another astute observation, Jeff.. kudos.

phreakre on February 28, 2007 4:32 AM

I like the question 'why we have to ask people to write FizzBuzz'. I think it is because the notion of what programming IS has changed (eroded?) over time. For example, in the late 60s if you claimed to be a programmer, you likely had the skills for FizzBuzz. But now I often hear of 'HTML programmers'. AFAIK, HTML doesn't have much in the way of flow control. Also, I rarely write many complicated algorithms any more, I just use existing stuff from the C++ STL or the JDK - but it is important that I know how to use them (compose with them, etc.), rather than just look for a magic method that does exactly what I want in a single line. 'There's no keyword or library function to do that' isn't an excuse to me.

Now my rant turns personal. I work for a government agency, and I find I get paid on the same scale as an 'HTML programmer'. I work on distributed simulation systems, and do a fair amount of system level coding. I've done a couple of web projects before I joined the gov't, using servlets, SQL, etc. In my experience I rarely meet people who can't write FizzBuzz in my recent work, but I encounter people doing web development who probably would have a tough time with FizzBuzz - and those same people (who haven't walked in my shoes) will remark how challenging their work is. My private thought is, if you think that's difficult, try my job for a day. And I have walked in their shoes. OK, my rant is done now.

Brad on February 28, 2007 4:49 AM

Pete:
In theory I have to agree, though it depends on how far you push readable+clear. Smart, gets the job done, follows instructions - that would be my first set of requirements.

Brandon on February 28, 2007 4:52 AM

Brandon:
There are good programmers who can solve problems with resources (again not specifically thinking of FizzBuzz here) and a lack of pressure that will undoubtedly make mistakes in an interview. I'd say their approach is far more important than the actual results in this situation.

Knowledge and experience can be acquired if a little lacking, but your approach to programming (I mean the way you think as a programmer when solving problems) is difficult to change once you have it.

Pete on February 28, 2007 5:01 AM

"Is there a term for people who compulsively answer rhetorical questions?"

Yes, programmers. Apparently...

Telos on February 28, 2007 5:13 AM

if(hedgerow.Contains(bustle))
{
alarmState = AlarmState.NotAlarmed;
bustle = SpringCleanForTheMayQueen();
}

Daniel on February 28, 2007 5:20 AM

if(hedgerow.bustle) {
alarmed = false;
}

mayQueen.springClean();

natron on February 28, 2007 5:20 AM

That's spooky. Stop it.

natron on February 28, 2007 5:23 AM

We ask questions like FizzBuzz because interviews are short, because programming involves a great many skills and concepts, and we might as well screen for the basics immediately, and because the question probably has high predictive value.

I wouldn't give a candidate more than 60 seconds of my time to demonstrate that he/she knew how to handle FizzBuzz before moving on. "You don't need to write code, just explain how you'd do it."

I interview a lot of people, these days mostly hardcore quants, with degrees in the hard sciences, who almost certainly had to sling code at some point, but who may not be very good at it. For me, the interesting side topic here is:

What is a good set of basic questions -- like FizzBuzz -- that one can use to quickly cover the bases of programming skills and concepts? To quickly determine if you're talking to the real McCoy?

There was some discussion and criticism of "puzzles" and "trick questions" on yesterday's thread. I'm not into tricks. I posted a couple of my standards yesterday, the "four cards" problem and the hash table question. In my experience, these questions have high predictive value. They're not remotely reliable on their own (not getting the four cards problem, all by itself, means very little), but combined with a substantial number of other problems, they draw a clear picture in a short period of time.

I'm looking for "Bladerunner"'s voice-comp test for programmers: "I'm going to ask you a series of simple questions..." Because for me, the hard part is separating the wheat from the chaff.

John Pirie on February 28, 2007 5:32 AM

When I was reading the non-solution comments with other more advanced questions, I thought that often the first idea I have is not the best. Quite often I figure out an improvement over night. I don't know how I would do in an interview expecting "instant" best answers. For example, on the "are two strings anagrams of each other" question, I thought:
sort and compare
count number of each char and compare counts
what if it is unicode? count with hash map?

BTW I have been writing assembly and embedded programs for 20 years and cannot remember ever swapping to variables "in place" by hand. (There areinstructions to do it on many processors that I have used.)

expr on February 28, 2007 5:34 AM

I tried to ask a question on this blog yesterday amid the torrent of code, but I'd like to ask it again since it was impossible to get a response. It basically went like this:
I'm by no means an excellent programmer, I've only studied C and C++ as a hobby for a few years and written a few thousand lines of code and some silly and incomplete 2d games. The alleged inability of CS majors to even solve the Fizzbuzz or equivalent, plus many poster's inability to have the social skills to not flood the blog with illegible, or "clever", code makes me think that I could be competitive for an entry level programming job, at least in C. I had never considered applying for a programming job before yesterday.

Is that a bad attitude? I really like coding but would I be simply adding to the wave of noobs in professional positions? Should we leave programming jobs to those who grok it in the highest degree?

blkmage on February 28, 2007 5:48 AM

so...why not use this to the advantage of codinghorror. Wright a weekly challenge or something. One, it could be fun and two. It might be a good way to learn from other people. There is never just one way of doing things. It would be interesting to see how other people solve problems.

Bryan

Bryan on February 28, 2007 5:49 AM

You're right, I don't play "Stairway to Heaven."

But I rock the Hell out of "Foggy Mountain Breakdown."

mrprogguy on February 28, 2007 5:54 AM

As a student programmer, after reading this, my first instinct was to create a 'solution'; Like the rest, I'm a compulsive problem solver. I've only been in classes for 4 months, yet feel like a task this simple should be redundant. During nightly practicals, I'll crank out a oversimplified templated singly linked list, just because I think that this may be what I would be requested to do in a professional environment. Things like loops and conditionals are such second nature to me, and even after only 4 months of program, I would assume that any 'senior programmer' would be able to turn out a little under one hundred bytes of code in the blink of an eye. I suppose that which is constantly reinforced at my school holds very true:

Learn the hardest things, and remember them. Don't 'learn and remember' the simple things, know them so well that they're the fiber of your very being.

Nitz on February 28, 2007 6:01 AM

In a professional environment it usually boils down to something related to an excel spreadsheet.

natron on February 28, 2007 6:06 AM

oops, sorry, I thought it was a job interview.


wait, does this mean i won't get the job?

;)

David H. on February 28, 2007 6:12 AM

No FizzBuzz?! DENIED!

Jae on February 28, 2007 6:20 AM

Maybe we compulsively answer FizzBuzz questions because many of us have Autistic Spectrum Disorders and saw the answer before completly reading the problem statement? Or it could be one upmanship.

Brian on February 28, 2007 6:27 AM

So, let me get this straight: you asserted that many programmers aren't worthy of the title, proposed a simple problem to establish some basic credibility, and were surprised when your readers commented?

Also just in: three seconds after you finish reading this sentences, you will be thinking about an elephant in a tutu.

Sam Leibowitz on February 28, 2007 6:35 AM

Daniel & natron: thanks for the laugh. :)

Charles on February 28, 2007 6:45 AM

Had I read the FizzBuzz topic right after the original post, I would not have felt 'compelled' to write a solution.

After seeing many other solutions in various languages, it became a fun thing to add. :)

Now, off to my hacked Guitar Hero II game, and Stairway! :)

Jadawin on February 28, 2007 6:49 AM

It really is embarassing that there's anyone out there who proffers themself as a professional developer that can't figure out how a modulus works.
It's not a bad idea to have applicants prove that they're not helpless without The Internets to copy and paste from, but what about the flipside of the coin? Why not put FizzBuzz in front of them and walk you through it, having them explain what it does? At the end of the day, I want to work with people who not only can write good code that works, I want them to be able to read so-so code that's mostly working and know that since they can read code, their first instinct to fix what's wrong won't be to deploy tactical nukes from geosynchronous orbit and start from scratch.

dave solomon on February 28, 2007 6:51 AM

Or more precisely, it's the programmer's /Smoke on the Water/...

Leo Comerford on February 28, 2007 6:54 AM

> I'm looking for "Bladerunner"'s voice-comp test for programmers

It's a "Voight-Kampf" test.

OK, that was needlessly nitpicky, but I just couldn't stop myself.

Dave C. on February 28, 2007 6:55 AM

@blkmage: How are you ever going to gain experience if you don't try for a job? There's a lot of code to be written out there, and not all of it needs someone who groks programming really deeply. To quote The Magic Schoolbus: "...get out there, take chances, get messy and make mistakes!" If you're anything like me, the way to grok programming more fully is to do it, and if you can get paid for it, so much the better.

@Pete: I think a number of programmers (several on my LJ, at any rate) see obfuscated/ultracompact code as a challenge, and a bit of a status symbol: "I can solve this problem in N statements!" "Oh, yeah? I can solve it in N-1 statements!" To some degree, it's a pissing contest. Looked at from another perspective, though, there's a certain joy to be had in being able to solve a problem in as few characters as possible. It likely won't make any difference in execution speed, but it may save a bit of time and tedium on the part of the coder. And readability really is in the eye of the beholder.

Full Disclosure: I'm one of those compulsive FizzBuzz solvers. :)

Kit Peters on February 28, 2007 6:57 AM

To Jeff's astonishment people were actually posting solutions to the simple code test. But really Jeff, when will a programmer not try to flex his might and show off his skills a bit. However, some people where trying to one up each other and the started to post code and forgot to do parts of the test, like print the number everywhere else or print FizzBuzz every 15 lines.

The author stated that a decent programmer should be able to write the code in under two minutes. But it's one of those tests that is so simply you have a chance not to follow the directions. As a lot of the people who were posting solutions didn't do.

So to me the test is a two-fold question. 1) Can you write a simple program and 2) Can you follow directions?

Tim on February 28, 2007 6:59 AM

One more thing - the sort of programmer that reads this blog *shouldn't* be above implementing FizzBuzz. Far from it - it's the sort of thing that one should do periodically to make sure one remembers how. :)

Kit Peters on February 28, 2007 7:00 AM

Actually, I thought that there was one interesting point about fizzbuzz itself.

The best solution obviously involves using modular arithmetic. If, by some strange twist of fate, the candidate did not know modular arithmetic, would that be an automatic no-hire?

By "not know" I mean that they don't know that most (all?) computer languages have an operator that gives you the remainder; not that they are completely "math illiterate".

What if they solved the problem using some other method (say, counters or repeated subtraction)?

Bill on February 28, 2007 7:28 AM

I found yesterday's Fizzbuzz post very encouraging. I am not currently employed as a programmer, but would very much like to be. I could write the Fizzbuzz program without a problem (albeit in BASIC…) and it is encouraging that even at my neophyte level, my genuine fascination with code puts me ahead of such a greater percentage of applicants!

The Egger on February 28, 2007 7:28 AM

Pete on February 28, 2007 04:23 AM
I'm sorry, but I disagree. I read about half the comments on the last post and didn't see one genuinely good solution to the problem. None contained a single comment, all utilised hard coded constants and most were just plain obfuscated.

That whooshing sound was the joke flying over your head. The main point of fizzbuzz was that it was incredibly easy a caveman could do it and people in here were just having fun.

As for writing comments: this was an interview question. Did you also scream that they put their code in the default package!!1!!

BlogReader on February 28, 2007 7:30 AM

I have a different take on the programmers taking up the challenges of the FizzBuzz problem (at least on tickletux's site).

Good programmers are creative, like a challenge and enjoy solving old problems in new, more elegant, ways. The way I'm reading those posts are thoughts on how to make it more elegant and efficient. And a way to show off different programming paradigms and language strengths.

Big, complex, monster problems are solved by breaking them down into smaller, more manageable problems. Seeing how programmers tackle problems in new ways is what I want to see from my candidates.

Love the Wayne's World reference, but this is different. Guitarists that play Stairway are trying to play it verbatim and often are not very good at it. However, if you played well enough to put your personality into it and make it yours then that's another thing altogether.

Ben Craigo on February 28, 2007 7:36 AM

This is how you respond when you get a passionate, creative reaction from programmers in response to your post? That's really lame. And I'm glad no one listened to you.

Seeing *idiomatic* Python, Ruby, Scheme, Common Lisp, Haskell, SmallTalk etc. solutions is edifying if you don't program in that particular language everyday. Lots of the solutions showed examples of some of the great features in those languages. Look at Raganwald's compose & carbonation functions if you don't believe me. And I'm not ashamed that I learned something from reading that.

Joe W. on February 28, 2007 7:39 AM

[quote] The best solution obviously involves using modular arithmetic. If, by some strange twist of fate, the candidate did not know modular arithmetic, would that be an automatic no-hire? [/quote]

I'd say no - there's plenty of other (admittedly sub-optimal) ways to do it. I think the point is that they can come up with *something* that works. You can always optimize later. :)

Ugly way to do it (gotta prove I can, y'know) - VBA, since that's what I'm using at work
Dim number As integer, Dim count3 As integer, Dim count5 As integer
count3 = 0
count5 = 0
For number = 1 To 100
count3 = count3 + 1
count5 = count5 + 1
If (count3 = 3 And count5 = 5) Then
Debug.Print "FizzBuzz"
count3 = 0
count5 = 0
ElseIf (count3 = 3) Then
Debug.Print "Fizz"
count3 = 0
ElseIf (count5 = 5) Then
Debug.Print "Buzz"
count5 = 0
Else
Debug.Print number
End If
Next number

Allen on February 28, 2007 8:07 AM

It might have been lost in the noise from yesterday, Jeff, but there are people trying to make Software Engineering a real trade.

For example, The Association of Professional Engineers of British Columbia has a "Software" designation. That's right - it's being treated the same as Civil, Mechanical, and Electrical Engineering. You get a degree, you work under other P.Engs for 4 years, then you take a professional practice exam.

http://www.apeg.bc.ca/reg/ProfessionalEngineer.html

It's a start.

There's also a planned change to make members of all disciplines take continuing education courses.

themagni on February 28, 2007 8:12 AM

Wait a sec. Does that mean you're lousy if you CAN solve it? Or does it mean your lousy if your not depressed about how lousy all the comp sci grads are? But wait, if I read this blog then all my lousiness is canceled right? I'm gonna put that on my resume.

andy on February 28, 2007 8:14 AM

The problem I saw was that everyone posted solutions in VBA, Windows SCripting Host, VB etc. How is that any solution? I think maybe the FizzBuzz should also analyze what language coders choose. WSH? VBA? your scaring me...

ryan on February 28, 2007 8:25 AM

@Bill: I think the only wrong answers would be either dead silence or sequential print statements with no loop or branches. It is hard to believe, yes, but plenty of people would just stare blankly at you or mutter strange excuses ("If I had my IDE" or "If I could research it on the net"). Freaky, but true. It’s a great first question.

Stu Thompson on February 28, 2007 8:35 AM

If the people who spent all that time writing code snippets here yesterday had, instead, written to their local universities/colleges/community colleges and asked them how this could happen, maybe something productive could have come from it.

Programmer, police thyself!

Also, I thought Brad's comment on the rise of HTML was on the mark. After reading through the a good chunk of those comments yesterday, I was talking with the wife about, essentially, the same thing. When we were taking programming classes back in the 70s, there really wasn't any such thing as a GUI (and certainly no HTML). Your I/O options consisted of "do you want a card punch machine with or without a working ribbon?"

What it works out to is that we spent almost no time programming UI stuff because the UI was primitive and unimportant: algorithms and data structures were important, UI wasn't.

My son is currently in his 3rd year of a CS degree. His first 2 years were "wasted" with all the stuff necessary to satisfy the "well-rounded person" requirements of the university. The first term of the actual CS degree stuff started with basic programming (FizzBuzz stuff). But, instead of moving on into linked lists and data structures, they spent the next term working on the GUI aspects of programming. Only this term are they back into what we used to consider to be actual programming.

It's too late to stop the flood of vitriol that will result from that previous paragraph. But, I do want to say that I understand why the school does that: it's a GUI world now and that stuff needs to be covered. But, what's the cost of that coverage? FizzBuzz failure?

David A. Lessnau on February 28, 2007 8:52 AM

ryan on February 28, 2007 08:25 AM
[snip]
The problem I saw was that everyone posted solutions in VBA, Windows SCripting Host, VB etc. How is that any solution? I think maybe the FizzBuzz should also analyze what language coders choose. WSH? VBA? your scaring me...
[/snip]

Real programmers adapt to the workplace to a certain extent, and are comfortable working with languages that aren't necessarily their ultimate favorite, in order to Get The Job Done (tm).

You cannot always just parade into a job and say "right, toss that lot and lets start over with xyz language".

Tim Gunter on February 28, 2007 9:14 AM

"Real programmers adapt to the workplace to a certain extent, and are comfortable working with languages that aren't necessarily their ultimate favorite, in order to Get The Job Done (tm)."

I agree, 11 years here, and have had to work on many VB, MTS COM+, perl, ATG Dynamo migrations. Not fun stuff. My problem was that this was their first shot off the hip. If it was C#, C++, C, Java even Python or Ruby but they chose WSH and VBA?!?

Do "Real Programmers(tm)" when they choose to write something choose the most hideous language of choice?

Play some golf! <a href="http://golf.shinh.org/p.rb?FizzBuzz">http://golf.shinh.org/p.rb?FizzBuzz</a>

ryan on February 28, 2007 9:19 AM

"Guitarpocalypse" Ha! Classic.

Hey, I noticed you prepended "www." to my domain. Touche my friend. Touche.

Haacked on February 28, 2007 9:19 AM

On a side topic

At least two posts yesterday mentioned that the swap using arithmetic operations a=a+b; b=a-b; a=a-b; fails in case of overflow.

This is incorrect, it is a property of 2's complement arithmetic that if a sequence of additions (that include subtractions) has a final result that ends up in the representation range, then the result will be correct irrespective of the presence of intermediary underflow or overflow. As most processors use 2's complement representation, the swap using arithmetic operations mostly works.

Strange but true, you can use the program below to convince yourself that it is indeed working in the case of a swap, irrespective of overflow or underflow (done on short so that the loops finish in a reasonable time).

#include "limits.h"

int main() {

int i ;
int j ;
short int a, aswapped ;
short int b, bswapped ;

for (i=SHRT_MIN; i <= SHRT_MAX ; i++) {
for (j=SHRT_MIN; j<= SHRT_MAX ; j++) {
a = i ; b = j ; aswapped = b ; bswapped = a ;
a = a+b ; b = a-b ; a = a-b ;
if ((aswapped != a) || (bswapped != b)) {
printf ("Swap failed for %d %d\n", aswapped, bswapped) ;
}
}
}
return 1 ;
}

Marc Delvaux on February 28, 2007 9:24 AM

Speaking for myself, I went off and implemented FizzBuzz after I read your previous post (but before I'd read the comments), and was satisfied that it worked correctly (I didn't post my implementation as a comment). That's partly because it looked like a fun little challenge that wouldn't take long, and partly because I think that this would be a good litmus test when I'm recruiting, and I want to be fair about it. Basically, I won't ask other people to do things that I'm not willing to do myself, so if I'm going to say to someone "You took 15 minutes to work it out? You suck!" then I want to be sure that it's a fair assessment by trying it myself first. In the same way, I've been doing some certifications that are way below my current skill level (e.g. ECDL) just so that I know what they measure, and how much attention I should pay to them if I see them on a CV.

John C. Kirk on February 28, 2007 9:24 AM

Did anybody write this in Assembler? :)

Martin Marconcini on February 28, 2007 9:37 AM

I was surprised at the number of solutions to the FizzBuzz problem as well, Fizz Buzz is a total waste of effort in my opinion. Also many of the solutions are very obfuscated.

But to Jeff's point, why the need for FizzBuzz:

It comes down to validation. If I am looking for a C# programmer, I am looking for some level of skill with that langauge. People fluff resumes, exaggerate, etc. So, we give the fizzbuzz question(s) to make sure they can do it.

Professional licensing would help here, but how are you going to license someone when the technology and toolset changes so rapidly?

Maybe a basic programming license in addition to certification in different langauges.

I am not talking about Microsoft here or any large company that hands out certificates, I think FizzBuzz shows the need for a governing body of programming/computer science that is nonprofit and independent.

If someone shows me a programming license, then there is no need for fizzbuzz at all, otherwise, they have to demostrate something about thier skills because all programmers need to produce code at some point.

Jon Raynor on February 28, 2007 9:40 AM

I too wrote a solution, though i didn't post it. I think John C. Kirk hit it on the head -- I wasn't trying to see if I could solve the problem, it was obvious. I wanted to see how quickly I could do it myself. Out of the people who posted solutions, I bet most of them timed themselves. It's not the solution that mattered, it was the race.

And then following the race, it's a matter of elegance -- how short can I make it? How fast can I make it? Does my favorite pet language beat the others?

Ethan on February 28, 2007 9:44 AM

Pete, regarding hardcoded constants:

That's funny--I saw some similar complaints in the original posting, and my thought was that I'd be more wary of these silly buggers complaining about hardcoded constants.

That's cargo cult programming: following rules that originally had a good purpopose--"avoid hardcoded constants"--without understanding why they are good rules, what problems they are intended to avoid, or when they do or don't apply. Taken to extremes, it's responsible for a good chunk of thedailywtf's horrors.

In this case, the problem description has the 3 and 5 right in it. Doing otherwise in the code that solves the problem is just obfuscation. It doesn't help with maintenance, because you don't yet know what direction the problem is going to go. Will the numbers change? Will a third case get added? Will we need to add support for output in French ("Le Fizzbuzz") and UK English ("Fizzbouzz")? Keep the code as simple as possible and maintenance is always easier.

Jeff on February 28, 2007 9:49 AM

If you use fizzbuzz at a litmus test for PHP programmers, look for something like

while($a<101){ echo (($a%3)!=0) ? $a : "Fizz"; $a++;}

vrs the 1,000 responses of looped if/when/while/for stuff that was posted.

This will actually play a part when I am looking at future coders, though we generally ask for site examples and extensive code samples as well as references.

:)

joeldg on February 28, 2007 9:49 AM

sry your Fizz has no Buzz

ryan on February 28, 2007 10:14 AM

"That's cargo cult programming: following rules that originally had a good purpopose--"avoid hardcoded constants"--without understanding why they are good rules"

Avoiding hard coded constants is almost always a good idea, as it makes your code more self-documenting and allows easier changes when the constant is used in multiple places (as many FizzBuzz solutions do with three special cases and two constants). If you think things like this rule and making code as readable as possible are bad ideas then you probably haven't had the same nightmare experiences working with other people's code that I have.

I work with embedded systems where people frequently litter the code with (hex) constants to set certain in registers (which can do anything in hardware -- no way to tell from a number). Even with comments (which may no longer be in sync with the code) it's virtually impossible to tell what they're trying to accomplish just by looking at it -- I spend literally hours each week pouring over data sheets for different devices trying to work out what each arcane constant is for.

Following such a rule is a (very) minor inconvenience to you, but can be a HUGE assistance to your colleagues (even the ones you will never meet).

Pete on February 28, 2007 10:32 AM

Based on the number of incorrect programs posted to the original article, I'd have to say the FizzBuzz test works. It's a shame such a test is needed.

Kuerwen on February 28, 2007 11:03 AM

Not surprised about the comments in the last one. I myself had put it all together in C++ in my head moments after reading the problem.


Didn't read most comments on the other pages, but was I the only one to question the wording of the question in that output should perhaps be(separate lines for readability, although the problem never mentioned newlines:

1
2
Fizz
4
5Buzz
Fizz
...
14
FizzFizzBuzz
16


Oddly, English is harder to understand and interpret than the code it asks for. Personally, I'm more satisfied with my answer than the most common one. But who wouldn't like their own answer more?


Is a test like FizzBuzz necessary? I'm a Junior in college working for dual majors in CompSci and Information Systems, and I'm disappointed with the quality of the students I see in my classes, especially my programming classes. Problems that "just make sense" to me seem like they're hard to grasp by other CS majors at my school. Am I tooting my own horn? I hope not, but it seems that where computers were once an area that only enthusiasts pursued there is now a lot of people going into CS/IS that are just looking for what they're told is a solid career path.

In a class of 30 of my peers with a CS major at my school, I would expect maybe 4 could solve this problem in under 5 minutes. I'm sure most of you put it together in your heads in well under a minute, with maybe a minute to write it out. When will "teaching students to be proficient programmers" actually mean a programmer that can, as Jeff so elegantly put it, "program".


/Warning "Shameless Self Plug located below"
I'm finishing my Junior year of college at Clarion University of Pennsylvania in mid-May. I am majoring in both Computer Science and Information Systems, with programming being my hobby and focus for career choice. If anyone's company (or one that they know of) is looking for any summer interns or temporary summertime entry-level programmers for any reason, please contact me. I'm in PA, but have no problem relocating for the summer, especially if the job would pay enough to afford a place to live and some food. Anyone with any opportunities or interested in a resume or any information please feel free to contact me at walwal31(at)hotmail(dot)com.

Shameless? Yes. But where else will I find a better group of programmers and locations that may actually be part of a company looking for summer work?

Keven Kalkbrenner on February 28, 2007 11:14 AM

You either have it or you don't.

If you have it you will make a great programmer if you stick with it.

If you don't you had better find something else to do besides making nightmares for people like me...

Rabid Wolverine on February 28, 2007 11:42 AM

Real men write it in brainf**k anyway...

(Not quite to spec, does 00-99, but that's a documentation issue).

++++++++++>>>>>>>>>>>>>>>>>>>>>++++
+++[<++++++++++>-]>+++++++[<+++++++
++++++++>-]>++[<+++++++++++++++++++
+++++++++++++++++++++++++++++++++++
+++++++>-]>++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++
++[<++>-]>+++++++++++++++++++++++++
++++++++[<++>-]++++++++++++++++++++
+++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++>+++++++
+++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++
++++++++++>++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++<<<<<<<
<<<<<<<<<<<<<<<<>++++++++++>+++++++
+++>>++++++[<++++++++>-]<<<>>>>>>>>
++>>>++++<<<<<<<<<<<[>[-]++++++++++
>>[-]>++++++[<++++++++>-]<<<[>>>>>>
>>>>>>>[-]+<<<<<<<<<<<<<>>>>>>>+>>>
+<<<>[-]>[-]<<[>+>+<<-]>[<+>-][-]++
+>[<->-][-]+<[>[-]<[-]]>[<<[-]>>>>>
>[-]<<<<>>>>>.>.>.>.<<<<<<<<[-]]<<>
>>>[-]>[-]<<[>+>+<<-]>[<+>-][-]++++
+>[<->-][-]+<[>[-]<[-]]>[<<[-]>>>[-
]<>>>>>>.>.>.>.<<<<<<<<<[-]]<<<<<<<
<<<<<>>>>>>>>>>>>>[<<<<<<<<<<<<<>.>
.<<>>>>>>>>>>>>>[-]]<<<<<<<<<<<<<>>
+<<<<<<<<.>>>>>>-]<>>+<<-]

Therac-25 on February 28, 2007 12:09 PM

It appears that my logic has failed. I was just in the shower when it occurred to me that I faulted.

Multiples of 15, under my above interpretation of the original problem, should read "FizzBuzzFizzBuzz".


I guess I failed :(

Keven Kalkbrenner on February 28, 2007 12:10 PM

I don't believe any of this. If this is true why am I working so hard. You mean I can spend the day cutting out paper dolls of code and I'd be as good as the guy next to me? (I always suspected I was better than you, Carl.)

fxp on February 28, 2007 12:22 PM

FizzBuzz was easy, the real sad truth is most programmers are not tech savvy enough to send me $10 via PayPal.

Dave on February 28, 2007 12:32 PM

I think it is important to reiterate the point that programming is not about syntax and quite often not about math; it's about solving problems. There are varying degrees of ability in solving problems, but I think that creativity, an immense drive to learn and an innate desire to improve something are core traits of a good programmer.

CS programs are designed to give you a broad overview of the Computer Science field. I personally think that this is valuable to persons who may not live and breath the IT industry and are not sure what areas that they are going to be interested in. Every field has it's specialists, I think that the "General Practitioner" in Computer Science is far less common than a specialist and should be the goal of anyone that is aspiring to be a great programmer. If your only tool is a hammer, then every problem becomes a nail.

At the same time, we as humans only have so much that we can focus on at once. In the book "Domain Driven Design" by Eric Evans, Mr. Evans talks about the need for a Ubiquitous Language to be used on Software projects so that there is no need for translation between programmers and domain experts. This reduces the amount of effort required to comprehend the overall system. A Senior Developer should be able to see the project in terms of the overall picture. Otherwise they can put their considerable talents to waste on sins such as premature optimization.

Finally, criticizing a programmer because they do not know the exact parameters or return value of a method is counter productive. Especially in the light of tools such as Google that can help to find hundreds of examples or docs on how to use that function. Einstein was asked for his phone number once and he looked it up in a phone book. The person who had asked was surprised that Einstein didn't know his own number and made a remark to Einstein about it. Einstein's response was "Why should I memorize something I can so easily get from a book?" Einstein followed by saying that he never memorized anything which could be looked up in less than two minutes.

YouTube made an impact because of the concept, not because some coder found the most elegant way possible of paginating the videos.

Matthew Purdon on February 28, 2007 12:33 PM

That be as it may, putting forth the idea is much like saying "Nobody can lick their own elbow": Whether it's true or false, everyone who reads it is going to try it.

Dante on February 28, 2007 12:43 PM

I'm not going to lie... I didn't do it as a chalange to your post, but I was afraid I couldn't do it :-/... Let's just say I was disappointed in myself. I couldn't remember how to format strings for printf() nor could I remember how to use cout... and I program everyday, except sunday :).

Jeremy on February 28, 2007 1:07 PM

Comments were down yesterday when I went there. But the answer is: very few (java) folks code in the language's syntax. Almost all code in some framework, and haven't addressed FizzBuzz low level problems in years, if not decades. And won't in any User Application. Doesn't make them lousy programmers.

BuggyFunBunny on February 28, 2007 1:07 PM

(Arguing with Pete over hardcoded constants and cargo cult programming)

You got me exactly backwards. I don't think readability is unimportant; I think it's critically important. That was the whole point! Separating out definitions for 3 and 5 does nothing good for the readability or maintainability of the solution.

I know that avoiding hardcoded constants is a good guideline, for just the sort of reason you give. But when you turn down that candidate for not following it, is it because they're a lousy programmer who doesn't even know the guideline, or a really good programmer who knows it and also knows when it doesn't apply?

For a really simple example of why it doesn't apply here: how do you print "Hello World" in your favorite language? is it something like this (using Python 'cause it's short):

print "Hello World"

or something like this:

import sys
destination = sys.stdout
string_to_print = "Hello World"
print >>destination, string_to_print

Would you really turn down a candidate who came up with the former instead of the latter?

Jeff on February 28, 2007 2:30 PM

Writing article about hard drives: -2
Having Wayne's World reference: +10

You have been redeemed, Jeff.

foobar on February 28, 2007 2:49 PM

"so...why not use this to the advantage of codinghorror. Wright a weekly challenge or something. One, it could be fun and two. It might be a good way to learn from other people. There is never just one way of doing things. It would be interesting to see how other people solve problems.

Bryan"

I wouldn't mind seeing a weekly (perhaps monthly) small challenge like Bryan has suggested, it would be a good way to get responses from your readers. I have this blog on my google homepage so whenever I notice a new post I will read it if I have time (which I usually do between classes).

As a side note...did anybody solve it for their TI-83 plus?
It took me a while due to my lack of syntax knowledge as well as not knowing if there is a remainder function, but it runs.

GO TI-83 plus!

-Dana

Dana on February 28, 2007 2:56 PM

As far as I'm concerned, the BrainF**k, Perl and Java solutions are the best. It's all about the Factory Pattern being reapplied.

When I applied to a certain large software company, there was a timed test for programming certain things in their framework that I would have taken had I gotten to go up there and interview. I'm overall glad I didn't get the job, but it was definitely interesting to see what they expected.

When I sent them in a really nice set of answers six hours later with quite a nice little GUI, I was pretty insulted to not get a full interview.

I think there's a line to how many questions like this you should be able to ask. Honestly, it's really expensive for me to spend four hours staring at a stupid problem. My first solution to this problem would be picked from the best I could find with Google or Experts Exchange with a freeware license. Any time I have a truly hard problem in the real world I get to go ask someone who knows or find an answer that doesn't suck, so why would it be any different during a test?

"Build me a Wikipedia-style intranet in the next eight months." Tends to make me think, "Why not just install the Wikimedia and spend a few weeks modding it?" Any other answer I consider silly beyond belief, and encouraging these answers is a cruddy way to do business.

Dylan Brams on February 28, 2007 4:18 PM

I think it struck a nerve -- a well coded algorithm to solve a "problem" than can be easily grasped gives one the chance to "create", solve, whatever, and some people got that buzz to try it out.

Used to be that we had less to "care about" -- there were no frameworks, browser issues, dev tools with a zillion options and windows, and event programming was still future except for catching keyboard interupts.

I was a math major at Cal and couldn't get into the CS department. Even though I did lots of engineering and numerical analysis coding, the concepts of registers, assembly code, and other vital nuts and bolts that you may never use but help one grasp the bigger picture were missed.

I was in "high" school when STH came out, but truthfully LZ's first album is still better. We made fun of Black Sabbath's "Iron Man" because it was only 3 chords, but listening to it today, the guitar solo is better than most of what I hear. So I have mellowed or today's guitar playing is not so good.

"Officially", the rock era of the late '60s/early 70s ended with Bad Company.

steve burch on February 28, 2007 4:43 PM

Maybe you should give us something tougher than FizzBuzz.

philihp on February 28, 2007 5:20 PM

The truly frightening thing is the large proportion of 'solutions' in the comments that are wrong. Bounds errors, logic errors, failure to read the spec errors, holy cow.

Definitely proof that the "average" developer should be doing something else for a living.

Todd Blanchard on February 28, 2007 7:55 PM

My thoughts on the problem 'sorting the sheep from the goats'

http://jimliveshere.spaces.live.com/blog/

Jim on February 28, 2007 9:04 PM

[quote] [quote] The best solution obviously involves using modular arithmetic. If, by some strange twist of fate, the candidate did not know modular arithmetic, would that be an automatic no-hire? [/quote]

I'd say no - there's plenty of other (admittedly sub-optimal) ways to do it. I think the point is that they can come up with *something* that works. You can always optimize later. :)[/quote]

Whatcha talking about! Modular arithmetic is slow slow slow! Your counting method is much much better!

I'd put some serious thought into improving it though, and I reckon I've come up with the required improvements to optimize further...


StringBuilder line = new StringBuilder();
StringBuilder lines = new StringBuilder();
for (uint i = 1, fizz = 1, buzz = 3; i <= 100; ++i, --fizz, --buzz)
{
if (fizz > 2)
line.Append("Fizz");
fizz = Math.Min(fizz, 2);

if (buzz > 4)
line.Append("Buzz");
buzz = Math.Min(buzz, 4);

if (line.Length == 0)
line.Append(i);

lines.AppendLine(line.ToString());
line.Remove(0, line.Length);
}
Console.WriteLine(lines);


(and come on, when you say you can't play Stairway, what's the first thing someone's gonna do...)

{grin}

Bonehead Barry on February 28, 2007 9:25 PM

Dana: Forget the TI-83! Your post has inspired me to write the HP48 version.

<< 1 100 FOR i i 5 MOD i 3 MOD IF DUP2 AND THEN DROP2 i ->STR ELSE "" "Fizz" IFTE SWAP "" "Buzz" IFTE + END NEXT >>

One of these days I should just write an RPL compiler for x86...

C-Mike on February 28, 2007 9:43 PM

Nobody commented their code! Okay, so we all understand this simple task but one of the biggest headaches is working with other people's code when they leave no clues to what they're trying to do. The benefits of using a top programmer to quickly write brilliant code are negated if the maintenance consequently takes forever.

Gary on March 1, 2007 2:23 AM

I too tried the solution, and I too timed myself. I think if you gave any small problem in any context you will get a lot of people trying to solve it for the hell of it.
I would agree that it is a slightly biased test in that to do it in a reasonable time it requires knowladge of the modulo operator. I guess I would expect decent programers to be aware of it, but still...

[ICR] on March 1, 2007 4:01 AM

Well, the length to which these comments have gone, and off the mark at that, is something to think about.

I've interviewed 100's of programmers over the years, and many of them (20%? I don't know) couldn't write fizzbuzz, and I would never recommend those for any programming job. In fact, if no one else were available, I would recommend hiring no one - adding these people would probably have a negative impact.

However, there's been a conversation around my office about the concept of a 'computer trade school', say, for non-programming computer roles. For example, desktop support, server or LAN admin, etc. Like the 'computer operator' of days past.

I know there are existing programs, some with more merit, some with less. And like the fizzbuzz solution I expect people will answer this a debate over the relative merit of existing education applied to a 'computer operator' role.

But I'm interested in if it is even possible to come up with a proper program. Everyone in my office is quite impressed at the quality of local tradesmen from the local community college. I think it would be valueable to everyone if that quality control could be applied to a non-programming computer trade. And, would it be necessary for these graduates to write fizzbuzz? I would hope even these graduates could write fizzbuzz, but they might never have to.

IMHO, all real programmers understand flow control, and those who don't aren't programmers (yet, until they do). I'm also surprised when people don't understand at least the concept of a stack, but I have met some reasonably productive programmers that don't - and they pick it up right away when it is explained. I think any fizzbuzz test that requires flow control is a good first line. For more advanced jobs further lines will be needed.

Last time I hired a student, I did 10 interviews, and one of the interview questions was "discuss the difference between assignment in C/C++ and Java". Everybody except 2 said they were the same, even when I tried to prod them a little. Only 2 of 10 understood the difference between objects and object references. Is this because Java is taught and pointers are neglected? Perhaps, but I don't think so, because the wrong 80% seemed to think Java assignment copied by value like C/C++.

I think some of the 80% might have done an OK job writing a program for me, but the task for the student was actually to use AspectJ to retrofit some instrumentation into some legacy code. One of the 2 that got this question was hired, and he did a fine job, and I had a great time acting as a reference for his job search on graduation.

But I don't think you'd need a guy like that to configure and maintain an Exchange e-mail server. Nor would you want that (he'd get bored), nor would he want that (he'd be bored) - overqualified.

Any thoughts on what a non-programming fizzbuzz test would be for hiring a desktop support/server/LAN admin?

Brad on March 1, 2007 4:02 AM

TristanK has some ideas on non-programming FizzBuzz:

http://blogs.technet.com/tristank/archive/2007/02/28/it-s-not-just-a-programming-problem.aspx

Feel free to email him directly if you need to, he's a great guy.

Jeff Atwood on March 1, 2007 4:47 AM

// C/C++ extensible version.
// If you can do easily extensible in C, you can do it extensible in any language.
// You can copy/paste this code and compile it.

#include <stdio.h>
int main(void)
{
&nbsp;&nbsp;&nbsp;&nbsp;int max = 100;
&nbsp;&nbsp;&nbsp;&nbsp;int i,j;
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;// just change this three lines to change the program
&nbsp;&nbsp;&nbsp;&nbsp;int size = 2;
&nbsp;&nbsp;&nbsp;&nbsp;int numbers[] = {3,5};
&nbsp;&nbsp;&nbsp;&nbsp;char* words[] = {"Fizz", "Buzz"};
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;bool printnumber;
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;for (i=1; i<max; i++)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printnumber = true;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (j=0; j<size; j++)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!(i% numbers[j]))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printnumber = false;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("%s", words[j]);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (printnumber)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("%d&#92;n", i);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf("&#92;n");
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;return 0;
}

/* now my comments:
Design patterns are for people that don't know lisp. They are all versions of the "universal pattern": the human compiler at work.
This is a good problem "because" it is short and can drive out bad programmers. More complex stuff takes more time you have in an interview.
And I coded this because people kept saying that there were no good answers. So at least one good answer should be posted.
*/

Nicolay77 on March 1, 2007 9:29 AM

# //alternating perl and java
# stairwaytoheaven.pl.java

$flag = exists ($ladywhoknows)
allThatGlitters.setColor(Color.gold)
she.buy("Stairway to Heaven");
if( she.getsThere() ) { she.knows(); }
foreach $c @store { @store[$c] = "closed"; }
if( she.oneword() ) { she.setCanGetWhatSheCameFor(true); }
# oh ohhohh
and she->buying("a stairway to heaven");
if( !she.wantsToBeSure() ) { boolean signOnTheWall = true; }
int sometimes = words.numOfMeanings();
assert sometimes = 2;

perljam on March 1, 2007 11:58 AM

Scott, you're so right. Those kick ass. I updated this article with one of the pics you selected:

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

Jeff Atwood on March 1, 2007 12:55 PM

ms tsql
sorry it's procedural

declare @bzr varchar(4);set nocount on;declare @onehundredniiiiinetynine int;set @onehundredniiiiinetynine=1;declare @rdir varchar(8);declare @200 int;set @200=1000*@onehundredniiiiinetynine/10;declare @onehundredniiiinetynine int;set @onehundredniiiiinetynine=@onehundredniiiiinetynine;declare @not int;set @onehundredniiiinetynine=1;declare @exists int;set @bzr = 'fizz';set @200=201-@onehundredniiiinetynine-(@onehundredniiiinetynine*(@200%201));set @not=0;while @onehundredniiiinetynine<=@200 begin set nocount on;declare @buzr varchar(200);set @exists=floor(21*@200/31415/*9*/);set @buzr=NULL;select @rdir=coalesce(fizzbuzz+nullif(fizz,@bzr)+nullif(fizz,'buzz')+nullif(fizz,@bzr+'buzz'),fizz) from (select convert(varchar(3),@onehundredniiiinetynine) as fizzbuzz, case @onehundredniiiinetynine%((7^4)%9) when @not then @bzr else '' end+case @onehundredniiiinetynine%(12&(77&54)^1) when @exists then 'buzz' else '' end as fizz) bitwise_nor;print @rdir+coalesce(@buzr+'fizz','') set nocount off;set @exists=NULL;set @onehundredniiiinetynine=@onehundredniiiinetynine+1;end;

nightsql on March 1, 2007 5:54 PM

Code should be readable. If a programmer can't read, how can you expect that programmer to read what they just wrote in code? Good code is readable. Just like you want to be able to read the resume.

What surprises me is that even if I can write a FizzBuzz solution, it still hasn't guaranteed me a job with any employer that wants a programmer.

#include <iostream>

main()
{
for( int i = 1 ; i <= 100 ; i ++ )
{
if( ( i % 3 ) && ( i % 5 ) )
std::cout << i << std::endl ;
else
std::cout
<< ( i % 3 ? "" : "Fizz" )
<< ( i % 5 ? "" : "Buzz" )
<< std::endl ;
}
}

dzonatas on March 2, 2007 3:51 AM

Hmm... I found a feature in your blog in the above message of mine, as it left out some text in my insertion. Do you see where?

dzonatas on March 2, 2007 4:04 AM

I'm not even a programmer, and when I read the FizzBuzz thing, the code popped up in my head, in BASIC. Literally five seconds.

Peril on March 2, 2007 6:39 AM

Why, oh why, I seem to like the spider guitar ?

Nicolay77 on March 2, 2007 11:40 AM

After reading this, the thing that popped into my head was "people like solving little programming problems". So I made a blog for a daily dose of little programming projects that should be completable in just about any language (most require the ability to output text and manipulate numbers, so it does limit it to a certain level) and in a relatively short amount of time. Today is day #3 for me, and I have 3 projects up already that are about the size and scope of FizzBuzz. If you have any interest, click my name and check it out.

Jae on March 2, 2007 12:30 PM

I feel slightly dirty having just posted a blatant plug like that...

Jae on March 2, 2007 12:35 PM

Hmm - Think I have an idea for a new killer video game here: "Programmer Hero". Start off with FizzBuzz, and progress up to The Traveling Salesman. Venues could be interview rooms at Google, MicroSoft, ZoomInfo (shameless plug).

Martin on March 2, 2007 2:03 PM

The interviewer who is expecting, and eventually selecting, a programmer to developing the FizzBuzz logic in less than couple of minutes, is actually trying to build a team for a project which is more than likely to lead to failure and waste millions of dollars and leading the project stakeholders to suicidal death. A programming skill is not something that may spontaneously be predicted and come up with the best logic suitable for a given scenario.

Akbar on March 5, 2007 6:10 AM

using System;
using System.Collections.Generic;
using System.Text;

namespace FizzBUzz
{
class Program
{
static void Main(string[] args)
{
for (int index = 1; index <= 100; index++)
{
if (index % 3 == 0 && index % 5 == 0)
{
// Print it out
Console.WriteLine("FizzBuzz");
}
else
{
if (index % 3 == 0)
{
// Print Fizz
Console.WriteLine("Fizz");
}
else
if (index % 5 == 0)
{
// Print Buzz
Console.WriteLine("Buzz");
}
}

if (index % 3 != 0 && index % 5 != 0)
{
// Print it out
Console.WriteLine(index.ToString());
}
}
}
}
}

Jehanzeb on March 6, 2007 1:35 AM

In fact, I did not solve FissBuzz within 2 minutes. I immediately had a question: "Will the special outputs change often or are they constant forever?".
If they change often, I think, most solutions are not very good, because adding another special output - like "Qux" if number % {7, 23, 58} == 0 - will be a bit more difficult.

I'd rather create something like this:

function FizzBuzz(int Start, int End, Hashtable Specials) {
for(int Counter = Start; Counter < End; Counter++) {
foreach(Specials as Constraints => Output) {
if(sum(map(fun(X) = Counter % X end)) == 0) print(Output);
} // foreach
} // for
} //function

(Pseudocode. Influenced by a lot of Stuff ;) )
Btw, this assumes A % B > 0. Who sees why? :P

Of course, the sum(map(...)) can be replaced by foldl for more obscurity and efficience :)

Hk on March 6, 2007 5:01 AM

I think the reason I was compelled to code FizzBuzz is because I had to prove to myself that I wasn't as incompetent as you described.

R. Mason on March 6, 2007 6:54 PM

(for (i 1 100)
(if
(= 0 (% i 15)) (set 'i "FizzBuzz")
(= 0 (% i 5)) (set 'i "Buzz")
(= 0 (% i 3)) (set 'i "Fizz"))
(println i))

newlisp on March 9, 2007 2:07 AM

I'm shocked how many people actually posted theyr own solution. Many of them just wasn't giving the right result.. forgetting to print the numbers.

I did a test me too, I was curious to see how much time it wold take for me. I think the point of the discussion was to say that many "developers" are unable to solve a simple problem in an acceptable time.
For everybody posted a solution without saying how much time did they spent on it.. well I think they havn't understood what was the "test" purpose. It's belivable that everybody sooner or later find the way.

My 2 cents

Max

MaxL on March 12, 2007 7:33 PM

The first thing that's happening here is people are thinking "Hmm, yes it sounds like a really simple problem anyone should be able to cope with, but I'd better check it myself to make sure there isn't a hidden twist".

The second thing is that once people find there's no twist, it strikes them as quite a neat little problem which could be used to compare languages or try out new forms of obfuscation.

So I can see why any of us who hears of this problem first tries it out in our favourite language, then our second favourite language, then the language we're currently trying to learn, then the language we hate, then the toy language we once invented, then in our favourite language in a silly way, ...

Matthew Huntbach on March 13, 2007 4:30 AM

Here's my solution in Smalltalk. It may not be the most elegant one, but, certainly, Smalltalk is the most elegant programming language.

" FizzBuzz test "

Transcript clear.
1 to: 100 do: [ :n |
(n \\ 3 = 0) ifTrue: [Transcript show: 'Fizz'].
(n \\ 5 = 0) ifTrue: [Transcript show: 'Buzz'].
((n \\ 3 ~= 0) & (n \\ 5 ~= 0)) ifTrue: [Transcript show: n printString].
Transcript cr.
]

Anthony Georgilas on March 13, 2007 9:14 AM

Here is my solution. It is written in 8051 assembly. You will need a 11.0592 MHz quart to run this thing :p

;*********************************
;* Program: fizzbuzz
;* Author: Samir Ben Abid (samirbenabid@linuxmail.org)
;* Description: Outputs the FizzBuzz test results to an rs232 port, 9600,8,0,n
;* P.S:
;* Compiled with Keil C51 running on Wine (lame!)
;*********************************


;*** CONSTANTS ***

; divider1
; the first divider's value
divider1 equ 3d

;divider2
; the second devider's value
divider2 equ 5d

; limit
; the maximum value that the fizzbizz program can reach. Must be between 0 and 100
limit equ 100d

;*** CODE ***

; Code segment at 0
cseg at 0
ljmp start ; avoir interrupt vectors
org 0x100 ; and go to a safer place
start: ; a.k.a here.
;
mov scon,#0x52 ; set UART to 8,0,n
mov tmod,#0x20 ; Timer1: autoreload
mov th1,#0xfe ; speed: 9600 bps
setb tr1 ; start Timer1

mov dptr,#intro ; load the intro and...
call emit ; beem it!

mov r7,#0 ; set counter to 0
compute:
cjne r7,#limit,continue ; are we finished with counting to 100?
jmp rest_in_peace ; Yes... rest in peace.
continue:
call do_crlf ; go to next line
mov r4,#1 ; set the (r7%3)? flag
inc r7 ; counter++
mov b,#divider1 ;
mov a,r7 ; divide the counter by three
div ab ;
mov a,b ; and get the reminder
jz do_fizz ; if it is null, do a fizz :)
next:
mov b,#divider2 ;
mov a,r7 ; divide the counter by five
div ab ;
mov a,b ; and get the reminder
jz do_buzz ; if it is null, do a buzz :D
mov a,r4 ; did we do a fizz?
jz compute ; if yes, reume the loop
call write_number ; else, write the number
jmp compute ; and resume the loop

rest_in_peace:
clr tr1 ; Stop Timer1
jmp $ ; AM STONED!

; do_fizz
; gets: nothing
; returns: 0 in r4
; description:
; Beems a "Fizz" through the UART
do_fizz:
mov dptr,#fizz ; load the fizz
call emit ; then display it
mov r4,#0 ; and leave a message: "I was here"
jmp next ; then resume your normal activity

; do_buzz
; gets: nothing
; returns: nothing
; description:
; Beems a "Bizz" through the UART
do_buzz:
mov dptr,#buzz ; load the buzz
call emit ; then display it
jmp compute ; then resume the loop

; do_crlf
; gets: nothing
; returns: nothing
; description:
; Beems the Carriage return/Line feed controle caracters through the UART.
do_crlf:
mov dptr,#crlf ; load crlf
call emit ; then send it
ret ; and return

; emit
; gets: the adress of the message to display in dptr
; returns: nothing
; description:
; Beems an ASCIIZ message, stored in the code memory, through the UART.
emit:
mov r6,#0 ; initialize the index to 0
bc_1:
mov a,r6 ;
inc r6 ; load the pointed byte
movc a,@a+dptr ;
jz fin ; if zero then return
jnb ti,$ ; if the last transmission isn't over, stay in your place
mov sbuf,a ; and transmit!
clr ti ; and clear ti to get further notifications :p
jmp bc_1 ; end of the loop
fin:
ret ; return

; emit_id
; gets: the digit's value in A (must be between 0 and 9)
; returns: nothing
; description:
; Translates a one-digit-bcd value located in A into Ascii and the beems it through the
; UART.
emit_id:
mov r5,a
mov a,#'0'
add a,r5
jnb ti,$
mov sbuf,a
clr ti
ret

; write_numer
; gets: the number to display in r7
; returns: nothing
; description:
; Beems the Ascii representation of the number located in r7 through the UART. r7 must
; be between 0 and 99
write_number:
mov a,r7 ;
mov b,#10d ; divide the number by 10
div ab ;
jz write_l ; if it si less than 10 then just write the modulo
call emit_id ; else, write the result (because r7<100) :)
write_l:
mov a,b ; prepare the parameters
call emit_id ; and send the digit
ret ; then return

; *** STATIC DATA ***

; fizz
; type: Asciiz string
; description:
; containes the fizz message
fizz: db "Fizz",0

; buzz
; type: Asciiz string
; description:
; containes the buzz message
buzz: db "Buzz",0

; intro
; type: Asciiz string
; description:
; contains the intro message.
; P.S:
; intro shares it's Asciiz 0 with crlf, 3 code bytes of economy :)
intro: db "The FizzBuzz test"

; crlf:
; type: Asciiz string
; description:
; containes the crlf byte couple
; P.S:
; shares itself and it's Asciiz 0 with intro
crlf: db 10,13,0

; Bye Bye :)
end

Samir on March 18, 2007 9:05 AM

I've liked the BrainF**k solution.
Any solution in INTERCAL? :)

Samir on March 18, 2007 9:10 AM

I love this example it is a prime way to weed out the candidates who don't understand the basic operators that come in very handy.

Nick Berardi on April 21, 2007 7:30 AM

<Groan>
The debate about proving oneself aside, this whole thing is symptomatic of a downward spiral in hiring by so called Human Resources.

I was recently multiply interviewed by a well-known internet search company (who shall obviously remain nameless) for a post in image processing. Now, I think it's fair to say I'm an expert in this field with over 12 years research experience and a PhD to boot. However, in one of the many interviews I was asked question after question on programming databases - about which I know approximately zero - by someone who had a list of set answers. Some of these questions required "real time" programming, ie. writing programs on the fly, which is damn near impossible. Needless to say that because of that one interview I wasn't hired.

On another occasion some years previous I was asked to program a Euclidean distance estimate function, which I did perfectly, only to be told that it was no good since it wasn't how their programmer had done it. This was a tacit acknowledgement that the person asking the question didn't actually know how to do it but could compare the two and see they weren't the same. [Incidentally, my solution was the more elegant of the two].

My points being:
1) This kind of mindless task is far easier to ask than to answer, so is perfect for HR robots looking to eliminate candiates a.s.a.p. with minimall effort. As such it should be avoided not encouraged..
2) It proves little about programming ability - which is a problem solving skill rather than a regurgitation skill. We all have access to the resources on the 'net in our daily work and knowing how to use *that* effectively is more important.

Z.

Zoinks on April 22, 2007 1:26 AM

It's so difficult:

for($i = 1; $i < 101; $i++) echo $i % 15 == 0 ? 'Fizz-Buzz' : ($i % 3 == 0 ? 'Fizz' : ($i % 5 == 0 ? 'Buzz' : $i)) , "\n";

...

sdfgdsfg on April 28, 2007 8:37 AM

I just enjoyed seeing how this problem was expressed in all the different languages... It's slightly more complicated than hello world, so it shows a little about those language's syntactic and logical structures.

I wrote it in Postscript, which was fun. I wrote 3 versions of it... the "normal" version, the compact speed-optimized unreadable/obfuscated version, the completely generalized version.

The final version allowed you to specify any range of numbers (1-100), any strings for replacement (fizz, buzz), any numbers to compare against (3,5), and any comparison logic to use via a named functioned (multiples of), so that you now have a function that will iterate over a range replacing integer values with string via whatever arbitrary comparison you wish...

Why? Because it was fun, and relaxing compared to the programming tasks I have to do all day at work. I became a programmer because I enjoy it. It's hard to maintain your enjoyment of it when "business interests" are constant destroying any fun you might be able to eek out of your work. So, doing stuff like this is akin to doing the crossword puzzles in the newspaper... It's no great feat, but it exercises your mind just the tiniest bit, and it's completely frivolous, which is less boring, and less stressful than not doing it.

-th

thoward on May 16, 2007 2:14 PM

Console.WriteLine("1\n2\nfizz\n4\nbuzz\nfizz\n7\n8\nfizz\nbuzz\n11\nfizz\n13\n14\nfizz\n16\n17\nfizz\n19\nbuzz\nfizz\n22\n23\nfizz\nbuzz\n26\nfizz\n28\n29\nfizz\n31\n32\nfizz\n34\nbuzz\nfizz\n37\n38\nfizz\nbuzz\n41\nfizz\n43\n44\nfizz\n46\n47\nfizz\n49\nbuzz\nfizz\n52\n53\nfizz\nbuzz\n56\nfizz\n58\n59\nfizz\n61\n62\nfizz\n64\nbuzz\nfizz\n67\n68\nfizz\nbuzz\n71\nfizz\n73\n74\nfizz\n76\n77\nfizz\n79\nbuzz\nfizz\n82\n83\nfizz\nbuzz\n86\nfizz\n88\n89\nfizz\n91\n92\nfizz\n94\nbuzz\nfizz\n97\n98\nfizz\nbuzz\n");

commenter on June 1, 2007 7:54 AM

I've been using FizzBuzz-type questions, but usually simpler than FizzBuzz, in interviews for 20 years now (I just dug out my first interview notes from 1987!). I've interviewed people for many types of programming job. What follows the FizzBuzz-type question will vary depending on the specific job, but I always start with the trivial one.

Why do I ask them to write Fizzbuzz? If they're lost when looking at that one, I can save everybody's time by wrapping up the interview quickly.

Jeff's question was "Why do we have to ask people to write FizzBuzz?"

1. Because a CS degree is not a guarantee of basic coding literacy. That's unfortunate, but true. Me, I think they should ask for their money back from the colleges that churned them out.

2. Because HR is now a game of tick-the-box. "Salary expectations within range? Check. Degree? Check. Two years of Java? Check. Able to program? Sorry, HR can't handle that one."

Last week, I interviewed 5 people, all with CS degrees. None of them answered the FizzBuzz-type question correctly, and only one of them came close. It was a bad week. :-(

jim on June 1, 2007 11:11 AM

I'm disappointed in the answers to the fizzbuzz problem that have been posted here. I never saw my favorite:

printf("1,2,FIZZ,4,BUZZ,5,FIZZ,7,8,FIZZ,BUZZ,11,FIZZ,13,14,FIZZBUZZ.....\n");

Cruise on June 1, 2007 12:08 PM

Kinda puts the world into perspective. I'm 12 years old, in 6th grade, and the fizzbuzz problem is ridiculously easy. Picked up C++ for dummies and within a few weeks, I can script (albeit not really well...).

jimmy on June 1, 2007 12:47 PM

I HAS A FizzBuzz in LOLCode (http://tinyurl.com/27eszt). Now I just need a compiler so I can test it...

HAI
CAN HAS STDIO?
I HAS A LOOPVAR
IM IN YR LOOP
IZ (LOOPVAR MOD 3 LIEK 0) AND (LOOPVAR MOD 5 LIEK 0)?
YARLY
VISIBLE "FizzBuzz"
NOWAI
IZ (LOOPVAR MOD 3 LIEK 0)?
YARLY
VISIBLE "Fizz"
NOWAI
IZ (LOOPVAR MOD 5 LIEK 0)?
YARLY
VISIBLE "Buzz"
NOWAI
VISIBILE LOOPVAR
KTHX
KTHX
KTHX
UP LOOPVAR!!1
IZ LOOPVAR BIGR THAN 100? KTHXBYE
IM OUTTA YR LOOP
KTHXBYE

OffBeatMammal on June 1, 2007 12:49 PM

"And instead of writing FizzBuzz code, they should be thinking about ways to prevent us from needing FizzBuzz code in the first place."

Is the same as saying...

"And instead of taking tests, they should be thinking about ways to prevent us from needing to take tests in the first place."

That is the dumbest thing I've heard today. How do you get people to prove they know what they know? It's called testing. Thanks for being an egotistical prick about it though.

I'll play stairway to heaven whenever I want!

i hate jimmy page on June 1, 2007 12:50 PM

This Fizzbuzz issue really is a problem though. I remember in first year, there were a bunch of people who couldn't code worth a damn. I figured they'd be weeded out by 2nd year. Nope. 3rd year? Nope. 4th year? Nope, they're still there, right beside me. Somehow, they manage to basically skimp by all the classes, without ever actually coding. My supervisor for my thesis says he even has this problem with graduate students that can't code! I think the issue is that, in my program at least, there aren't that many hardcore coding classes. And, basically all the hard coding courses past 1st year put you in groups to do work... and large groups at that, since the classes are so big. So, if these people can manage to squeeze by first year, then it only gets easier to weasel by in 2nd, 3rd, and 4th year, since they simply let other group members handle the coding part of the project... or they may do nothing at all. The few courses I've taken that have hard individual coding assignments that are actually worth something are only required by certain streams. Many people also manage to graduate w/o the courses by getting substitutes.

Tom S on June 1, 2007 5:01 PM

Good point. I read the FizzBuzz replies, and have to say, I actually was asked to write a FizzBuzz once for a job interview. They told me they were impressed, which only depressed me. If knowing how to make use of modulus arithmetic and a for loop is impressive, then what is the world coming to?

Still, I got an interview out of it. But no job - I think that was because I couldn't encapsulate the differences between C and Java during the interview. And/or, I wasn't a C# guru, though not exactly a C# moron.

Wesley Parish on June 3, 2007 5:30 AM

I'm also depressed by the paucity of languages most FizzBuzz respondents used. I mean, what, no COBOL? No FORTRAN? No Algol68? No PL/I? No IBM S/390 HLASM? No Ada? No Bliss?

And only one APL!

Sheesh!

Wesley Parish on June 3, 2007 5:47 AM

"The interviewer who is expecting, and eventually selecting, a programmer to developing the FizzBuzz logic in less than couple of minutes, is actually trying to build a team for a project which is more than likely to lead to failure and waste millions of dollars and leading the project stakeholders to suicidal death. A programming skill is not something that may spontaneously be predicted and come up with the best logic suitable for a given scenario.
Akbar on March 5, 2007 06:10 AM "

Looks like someone failed the test. I guess we do need a test to see if a person can think... even if an 8 year old could pass it

danium on June 26, 2007 1:35 AM

I'm just amazed how many of the replies that have 'solutions' are actually wrong and have various errors!

So there is more than one point to the FizzBuzz test:
1) Can the application understand programming languages at all?
2) Does the application think carefully about their answer, and check it?

Rut the Nut on June 29, 2007 1:50 PM

I haven't been subjected to tests of my skill yet, and inasmuch as I think it would be "oh so much fun" I have to say that I find it a little bit ludicrous to put people down. A lot of people say they are programmers when really they are not and couldn't tell you what was wrong with a page of code if it was written entirely in English and not in code at all. But lots of people do that...and not just in coding and programming. I run into people every day who tell me that they are Media Buyers and I after two questions about their job I know that they don't even know the title means. But at least they're trying...and I think that's a little more important. This sounds more like an argument I would have with a standardista that thinks people shouldn't be allowed to post sites on the web unless they have received training for it. What's the point of asking the question if you already know the answer?

t-shirts on August 26, 2007 12:29 PM

When I applied for a Software Engineering job, I was actually given the FizzBuzz problem from this blog as a "test." After getting the job, I was told that credentials don't always mean a person is qualified, and that they used FizzBuzz to weed out the poor applicants.

Lianne on September 5, 2007 8:35 AM

Very interesting blog, and I think you’ve pointed out one of the problems that’s going to appear in any profession, whether it be guitar players or programmers. There will always be those people out there who don’t feel the need to read anything or learn anything new. They already think they know it all and that they can’t learn anything from the programming community. As you said, it’s these people who need the FizzBuzz test, but it’s also these people who are never going to understand WHY they need it. It’s a rather sad thought, but it’s true. Of course, I don’t think all programmers who don’t read blogs are like this – some, I think, just have no desire to interact with the community (some are loners by nature), and some probably just don’t have time. I know there are weeks where I go without reading all the blogs I normally like to just because there are only so many hours in the day….

baby on October 12, 2007 12:31 PM

You might be shooting for a rational discussion of Stairway to Heaven as a way to measure minimum levels of guitar competence.

Well, you got us off the guitarpocalypse, but I think rational was overoptimistic.

deworde on November 20, 2007 4:06 AM

Obligatory xkcd: <a href="http://xkcd.com/356/">Nerd Sniping</a>

Anonymous on January 24, 2008 6:12 AM

Forgot the link: http://xkcd.com/356/

Anonymous on January 24, 2008 6:13 AM

Well, here I was thinking that I was about to be sooo clever:
"So I guess that this isn't the time to write my solution?"

Then I saw that a few already had written their solution. No, not as a joke. We live in a world of dumbasses, folks.

(No offense to those who DID write their scripts here, but.. C'mon!)

saintpretz59 on January 24, 2008 3:09 PM

This is really Stupid!
There are some freaks out there who just want to see the code they pick up from this blog. I recently went for interview and the only thing he ask me is problem(fizz buzz), from 1...100
first i was thingking it may be a really big problem or there should be some catch but then i just wrote it
I wrote the code in Java and then he told me there is bug because you I didn't put less than & equal(both), i just used <100 , what a asshole ?
He said that he got disappointed ! that made me nervous
then he gave me the problem of reversing the numbers in a Char Array and by then i was king of nervous and used the method to copy to another array and reverse the order. He told me that take to much memory & not a good solution & then bye.....bye
I am ready to bit that he is not smarter than me in any way and i face him in a normal way not the interview i will kick his ass in technology and programing


I am not against test or testing with basic problems but at least try to understand the logic people use to solve the Problem instead of pin pointing that u didn't write both less than or equal sign.
I came home and within couple of minutes i wrote the test case run the both problems successfully.

In my opinion the person who is interviewing should have a understanding of his fields and positive attitude to hire the people and not just this FIZZ BUZZ problem alone.

One thing more he was just taking of reading blogs , C'mon
there are freaks who spend all their time on blogs, who the hill in this world has that much time to read all this bull and write all the time.
get a life people......go out do something ....i mean it!
People has work, kids, wife and parents to take care
Its gr8 to learn the new tech but not from BLOGS.


hunter on January 30, 2008 8:18 PM

The Excel Solution:

Paste the following formula into a cell on row 1, then select the bottom corner of the cell and drag down to row 100:

=IF(NOT(IF(AND(NOT(MOD(ROW(),3)),NOT(MOD(ROW(),5))),0,1))=TRUE,"fizzbuzz",IF(IF(MOD(ROW(),5),FALSE,TRUE)=TRUE,"buzz",IF(IF(MOD(ROW(),3),FALSE,TRUE)=TRUE,"fizz",ROW())))

Neil Kimber on February 25, 2008 10:26 AM

NICE!!!

ian on February 27, 2008 12:43 AM

(define (fizzbuzz n)
(let ((test (cond ((= 0 (modulo n 15)) "Fizzbuzz")
((= 0 (modulo n 5)) "Fizz")
((= 0 (modulo n 3)) "Buzz")
(else n))))
(if (= n 1) (list n)
(cons test (fizzbuzz (- n 1))))))

(map print (fizzbuzz 100))

Joe on May 17, 2008 7:22 PM

Concerning the variable swapping problem form the previous thread:

A simple solution in python ;-)

a, b = 3, 5
a, b = b, a

Anonymous on June 17, 2008 1:42 PM
Content (c) 2009 Jeff Atwood. Logo image used with permission of the author. (c) 1993 Steven C. McConnell. All Rights Reserved.