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

Actually I got asked a really simple question the last interview I had: given two rectangles in space, how do you test whether they overlap? I faltered for a moment, and remarked that I'd never actually done that before and had no idea how to do it. Then I got a piece of paper and did it. Really easy of course, but I think the interviewers got more information out of that than if I had automatically known how to do it.

Anyway, FizzBuzz is an ideal problem in which to be clever and use goto!

Sorry I can't resist.

for(int i = 1; i = 100; ++i)
{
if(i % 3 == 0) { std::cout "Fizz"; goto fizzbuzz_newline; }
if(i % 5 == 0) { std::cout "Buzz"; goto fizzbuzz_newline; }
std::cout i;
fizzbuzz_newline:
std::cout endl;
}


Unless you want the object-oriented C++ version:
http://interreality.org/~reed/tmp/fb.cc

Reed Hedges on February 27, 2007 10:12 AM

AndyToo wrote:
"I've been making a decent living from programming for over ten years, and if I may say so, I write some damn good code."

and 90% of people who say they're good programmers are actually horrible. :)

no offense, but if you've never had to use recursion in 10 years of "programming," then i highly doubt your solutions are optimal... heck i'm just a lowly front-end programmer and i definitely have to use recursion from time to time.

nabby on February 27, 2007 10:12 AM

Chris, I'm with you on being wary of the precision of the writer in a lot of questions. I always wanted to argue with the multiple-choice authors when I was back in school.

That's why I like that song that goes:

"I can't see me loving nobody but you for all my life"

Just how precise is that?

Patrick on February 27, 2007 10:13 AM

It's funny to see some of the solutions. I am in no means a "hard core" programmer (I didn't know if VB had a MOD function since I haven't used that since I did Pascal back in college). But it's one of those tests that is so simply you have a chance not to follow the directions.

This took me about a minute to write, if I had more time I would have found out if MOD was better to use. But it covers the requirements: 1) Loop 1 to 100, 2) print FizzBuzz every 15, 3) print Buzz every 5 and 4) print Fizz every 3.

And I would have asked the clarification if they supercede each other or if you would need to print Fizz Buzz FizzBuzz every 15.

Sorry Jeff for posting a solution, but if you can memorize something like this for a job interview, then you can write a loop anyway.

CODE
'VB6
Const fizz = 3
Const buzz = 5
Const loopEnd = 100
Dim x
For x = 1 To loopEnd
If x / (fizz * buzz) = Round(x / (fizz * buzz), 0) Then
Debug.Print "FizzBuzz"
ElseIf x / buzz = Round(x / buzz, 0) Then
Debug.Print "buzz"
ElseIf x / fizz = Round(x / fizz, 0) Then
Debug.Print "Fizz"
Else
Debug.Print x
End If
Next
/CODE

Tim on February 27, 2007 10:15 AM

I say, all the fucking better. The more shitty programmers there are out there in the world, the more in-demand us programmers that can actually think are. I say, let 99% of the programmers be dullards, so they can pay their salaries to me!

By the way, that algorithm can be written in like 9 lines:

for( int i=1; i101; i++ )
if( i % 3 == 0 i % 5 == 0 )
System.out.println( "FizzBuzz" );
else if( i % 3 == 0 )
System.out.println( "Fizz" );
else if( i % 5 == 0 )
System.out.println( "Buzz" );
else
System.out.println( i );

DONE! Java all.

N.E.R.D. on February 27, 2007 10:16 AM

Nick Franceschina's solution is nearly perfect. The only thing that is needed is to put the isBuzz and isFizz methods behind some webservice calls, then it's the perfect solution. Concise AND flexible. ;)

Joe on February 27, 2007 10:19 AM

I do not know of anyone in my Computer Science graduating class that could not write a version of this in java/c++ and at least one other language in under 5 minutes.

Who are you interviewing, and how are they getting these interviews?

Troy on February 27, 2007 10:19 AM

for (int i=1; i = 100; i++) {
Console.WriteLine(new object[] { "FizzBuzz", "Fizz", "Buzz", i}
["033132133123133"[i % 15]-'0']);
}

xd on February 27, 2007 10:25 AM

couldn't help myself, a one liner in php

while($a101){ echo (($a%3)!=0) ? $a."\n" : "Fizz\n"; $a++;}

Cheers

joeldg on February 27, 2007 10:25 AM

i'm a professional (web) developer, often changing between php, classic asp, vba, vb.net/c#.net, sql, javascript, html, etc., etc. we do customizations to sites that have been written already.

the thing is, if you asked me to write a for loop from 1 to 10, i may get it syntactically wrong if i've been coding in a different language recently.

so, to me, i think asking people to code at an interview isn't necessarily a great assessment of their ability.

Thimble on February 27, 2007 10:27 AM

for (int i=1; i = 100; i++) {
Console.WriteLine(new object[] { "FizzBuzz", "Fizz", "Buzz", i}
["033132133123133"[i % 15]-'0']);
}

xd on February 27, 2007 10:28 AM

Sadly, the "can't write FizzBuzz" guys end up being promoted more often than not too.

The realities of the modern work place is that it's more important for a programmer to be able to update his milestones in Microsoft Project and draw his designs in Visio that exports to PowerPoint than to actually deliver on his milestones.

JMXZ on February 27, 2007 10:31 AM

There is very much truth to what you said. Don't know about the "statistics" you present, but real-world proficiency seems to be a problem in many fields. In any case, here's my two cents in about three minutes (not the only way, I know). It is HTML for the purpose of presenting HTML (hence the commented code):

!--
html
head
/head
script
for (i = 1; i = 100; i++) {
switch (i%15){
case 0:
document.writeln("FizzBuzzbr/");
break;
case 5:
document.writeln("Buzzbr/");
break;
case 10:
document.writeln("Buzzbr/");
break;
case 3:
document.writeln("Fizzbr/");
break;
case 6:
document.writeln("Fizzbr/");
break;
case 9:
document.writeln("Fizzbr/");
break;
case 12:
document.writeln("Fizzbr/");
break;
default:
document.writeln(i + "br/");
break;
}
}
/script
/html
--

Thanks for the observations and insight :)

Peter on February 27, 2007 10:34 AM

I'm lame for even posting this...

Java. 5 min. Including testing. For production code I'd bother with comments and even a lame test case. Suck on it.


public class FB {
public static void main(String [] args){
for(int i = 1; i = 100 ; i++){
String out = "";
if(i % 3 == 0){
out = "Fizz";
}
if( i % 5 == 0){
out += "Buzz";
}
if(out.length() 0){
System.out.println( out);
}else{
System.out.println(i);
}
}
}
}

dave on February 27, 2007 10:35 AM

Obviously is so many people do not answer this, then there might be something wrong with the question.

I have been in interviews where some monkey asks me to find syntax bugs by hand...what the hell is the IDE for ! You might as well give a professional author a spelling quiz (what, you never heard of a spell checker!)

I get tasked this kind of stuff during an interview these days I just leave. It is a waste of my time. The last kind of place I want to work it is one where I am asked to write menial pieces of code at a moments notice without any planning or forethought and have someone look over my shoulder the whole time. And I certainly don't want to work with techhie freaks who only think about code syntax and the penis sizes of various star wars characters all day long

Yes, I have a PHD, developing hard core quantum meahnics simulation code. Yes, I have managed and coded commercial products that are in the market.


If you want to ask someone to do some work, then you should simulate the work environment. Let them bring in their environment, a laptop, hook them up to the internet so they have access to all of their resources. Tell them what you are going to be discussing so they can review what they need to know. Give them some time to think about what is going on? Then ask them to do something non-trivial which actually reflects the job they are being interviewed for.

Beleive it or butt munches, not everyone spends their free time memorizing the java syntax or solving high school puzzles.

More importantly and most accurately, not every stores and processes information in their mind in the same way.

I program all day every single day. That does not mean I will be able to recall the information at a momments notice or have the interest in writing code on the blackboard during a conversation. I simply don't store and process the information that way--oh, and chance are, I don't really want to spend my days talking to geeks all day long about trivial things.

Have any of you little nerds every played a sport? Have you tried to
do a back flip or hit a ball when someone is talking to you? For god's sake, go get a damn book on how the brain stores and processes and retrieves information.

Learn how to interview for the job, not your ego!

Chalres H Martin on February 27, 2007 10:37 AM

1. After f in hex comes 10.

2. Swap two variables (regardless of type)

list($b, $a) = array($a, $b);

3. Fizzbuzz in PHP:

foreach (range(1,100) as $i) {
if (!($i % 3)) $o = 'Fizz';
if (!($i % 5)) $o .= 'Buzz';
if (!$o) $o = $i;
echo $o . "\n";
unset($o);
}

Do I get the job? ;-)

Douglas Clifton on February 27, 2007 10:39 AM

Yes this is sad, but I had to type it up...

class Program
{
private const string Fizz = "Fizz";
private const string Buzz = "Buzz";

static void Main(string[] args)
{
for (int i = 1; i = 100; i++)
{
bool bMultipleOf3 = (i % 3 == 0);
bool bMultipleOf5 = (i % 5 == 0);

if (bMultipleOf3)
{
Console.Write(Fizz);
}
if (bMultipleOf5)
{
Console.Write(Buzz);
}

if (!(bMultipleOf3 || bMultipleOf5))
{
Console.Write(i);
}

Console.WriteLine();
}
Console.ReadLine();
}
}

Smirk on February 27, 2007 10:40 AM

Ha! I dropped out of CS in my third year to go into the clergy, and 13 years later I still was able to write FizzBuzz in C++ in about 4 minutes. Now for the real prize: CAN ANYONE WRITE IT IN ASSEMBLY?

Peter on February 27, 2007 10:42 AM

Stu,

Fortunately, the world doesn't revolve around your personal definitions of words. If you say answering 0x0f + 0x01 is a requirement to meet your definition of a programmer, then in your head it is. The world outside your head goes on without a single thought about who you are or what you believe.

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

Well, in your case that must be true because you have a personal definition of 'great', and that's just.. uh, GREAT. Some of those people you passed up for not answering 0x10, by law of averages, are probably working on projects just as demanding as your projects if not more so, making much more than you now (assuming you rejected enough candidates). And they STILL don't know HEX and the world doesn't care.

Now, as for not being able to get FizzBuzz down...You're probably on to something there.

globualcluster on February 28, 2007 1:01 AM

Here is my code to produce my solution:

#include stdio.h
int main(void)
{
printf("#include stdio.h\nint main(void)\n{\n");
int i;
for (i = 1; i = 100; i++)
{
printf("\tprintf(\"");
if (i % 3 == 0 i % 5 == 0)
printf("FizzBuzz");
else if (i % 3 == 0)
printf("Fizz");
else if (i % 5 == 0)
printf("Buzz");
else
printf("%d", i);
printf("\");\n");
}
printf("\treturn 0;\n}\n");
return 0;
}

Sam Collinson on February 28, 2007 1:03 AM

It took me 2.5 minutes to flesh out a working fizzbuzz program in C. it took me another 2 minutes to make the program output more elegantly and to learn how to use the modulus operator (%)

zeroth404 on February 28, 2007 1:03 AM

The appropriate response, if in interviewing you I ask you to do the FizzBuzz task, is to say (in a loud and clear voice), "Has the customer written the automated acceptance test yet?"

Bill Tozier on February 28, 2007 1:04 AM

After 10 years writing C in low power embedded systems, including a fair bit of interviewing, what seems more interesting than asking candidates for a solution to a given problem is to explore their reasoning while arriving at the solution.

Oh, and VB isn't a programming language.

Toby on February 28, 2007 1:09 AM

VB isn't a programming language? Neither is C. C is for girls. Why don't you write in pure machine language like the rest of us men?

Alan B on February 28, 2007 1:17 AM

Thanks Alan B, I wish there were more girls using C, it would make the office a much more interesting place to be. Why not use pure machine language? It's not portable and any company that wrote a significant portion of it's product like that wouldn't exist for long.

Naturally VB has its place but interviewing for C (or even assembly coding) jobs is so much more fun as there are so many more subtle issues to discuss than in highly abstract languages. For example above many posters have made statements about 'inefficient code', but nowhere in the design was efficiency stated as a requirement.

Toby on February 28, 2007 1:26 AM

Why are you programmers posting solutions? Do you really need to prove yourselves to an anonymous horde that you are in fact number 200, and not number 199? Are you in the top 1% because you can do this ridiculously simple task, or are you in the top 99.9801% as Joel Spolsky points out in his article? I'm thinking it's the latter.

Why on February 28, 2007 1:29 AM

To have something extravagant ...

#_SET:A=[1..100]#
#_FOREACH:A=LINE#
#_BEGIN_DELETE_IFNOT:LINE%3==0#FIZZ#_END_DELETE_IFNOT##_BEGIN_DELETE_IFNOT:LINE%5==0#BUZZ#_END_DELETE_IFNOT##_BEGIN_DELETE_IF:LINE%3==0||LINE%5==0##LINE##_END_DELETE_IF#
#_ENDFOREACH#

:)

Hinek on February 28, 2007 1:31 AM

Sorry, syntax error ... should be:
#_BEGIN_FOREACH ... _END_FOREACH#

Hinek on February 28, 2007 1:33 AM

Erm.. why would I want to Fizz my Buzz with a FizzBuzz?

I agree with the article, I think there are too many people out there who don't know how to write code in their head..

But..

That doesn't make them a bad coder or designer to be apt. Coding has become so abstract that most modern coders tend to be designers due to working with heavily gui based apps from Windows form coding to Web apps. So we could blame MS for doing this, but its not really their fault.

The days of the lone coder are gone, most if not all coders have no need to learn or retain any of the stuff they get taught in their college/uni and certainly its not a requirement in a job.

However I think coding should be about architecting a solution and that means working from the ground up. A good coder is someone who has knowledge of each area they are interacting with, not necessarily deep knowledge of a technical component but enough of an understanding to appreciate how their solution will fit into the wider picture.

Coding should be about elegance. It should be like designing a really well made web page that employs lush CSS and is a visual treat to look at. Code should be the same, well commented and fluid in its layout making the code appealing to read.

I have come across too many coders who simply code out of need, usually to meet out of proportion expectations resulting in badly formed code or a solution that has far too many shortcuts in place.

Each to their own though, every problem has a particular solution however I think what this article was touching on was the fact that the core foundation skills of a coder are not present in most interview cases and this is worrying but I think a growing trend.

When you have hand-holding applications like Visual Studio.NET there is no real need to retain information as you can for the most part, cut and paste your way to a solution. :P

Adios,

T

Tahir on February 28, 2007 1:34 AM

I like mine in php... you can set the index and how many you want to do.

?php
//FizzBuzz
Function FizzBuzz($index, $num) {
for($i = $index; $i=$num; $i++) {
if($i%3==0 $i%5==0) {
echo "FizzBuzzbr /";
}
else {
if($i%3==0) {
echo "Fizzbr /";
}
elseif($i%5==0) {
echo "Buzzbr /";
}
else {
echo "$ibr /";
}
}
}
}

FizzBuzz(1,100);

?

dcshaw87 on February 28, 2007 1:40 AM

"Oh, and VB isn't a programming language."

This monkey does not even know that VB was a huge success for MS.
It is the most successful and productive language alongwith Java. I wonder if anyone uses C for application programming.

Shirish on February 28, 2007 1:42 AM

What is funny to me is how the majority of people who wrote there code on here did the fizz/buzz portion correctly but forgot to print the numbers to screen for the rest.
Maybe the programming world just needs a little attention to detail instilled in them.
You should put up a stat on how many people actually tried to post the code on here and how many of them got it correct!...
Mushoo

Mushoo on February 28, 2007 1:53 AM

I think you are being too idealistic.

Being able to code does NOT make a good programmer?

Its all about resourcing?
http://www.google.com/codesearch
And getting the job done.

Nathan C on February 28, 2007 1:56 AM

a,b = b,a

Ruby rocks :)

bla on February 28, 2007 1:57 AM

Print “1”
Print “2”
Print “Fizz”
Print “4”
Print “Buzz”
Print “Fizz”
Print “7”
Print "8"
Print "Fizz"
Print "10"
Print "Doh!"
Print "Fizz"
Print "13"
Print "14"
Print "FizzBuzz" -- which most peeps above forgot

and so on.
I can't see what the fuss is..

Damian on February 28, 2007 1:59 AM

Jeff, give a programmer a clear spec, and they'll do it! It's no wonder so many people immediatley started tapping away and created their solutions!

It when real world specifications get handed to programmers and the programmers have to spend 80% of the project time getting the specification clarified.


Adrian on February 28, 2007 2:00 AM

Very easy in C#:

private void FizzBuzz() {
string fizz;
string buzz;

for (int i = 1; i = 100; i++) {
fizz = null; buzz = null;

if (i % 3 == 0) {
fizz = "Fizz";
}
if (i % 5 == 0) {
buzz = "Buzz";
}
if (fizz != null || buzz != null) {
Console.WriteLine(fizz + buzz);
}
else {
Console.WriteLine(i.ToString());
}
}
}

Alex W. on February 28, 2007 2:02 AM

No brainfuck solutions? C'mon guys

ddh on February 28, 2007 2:15 AM

Surely this is a test about reading the question (i.e. outputting the numbers)
and efficiency, minimising the number of conditional tests.

So the mod3 mod5 elegant solution misses the non replaced numbers and does 2 conditional checks per loop

This is better:

while(i++ i=100)
{
if(i%3)//most likely so first
write("Fizz")
if((i%5))//next likely
write("Fizz")
else if (i%5))//next likely
write("Fizz")
else
write(i)
}

even with this for a non replaced number all 3 conditions are checked first

Peter Stone on February 28, 2007 2:17 AM

Writing a program that satisfies your FizzBuzz specification is trivial in any language. The solve the specification you can simply write out the precomputed solution:

println("1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz ...");

This gives you also the best runtime performance ...

Alex on February 28, 2007 2:32 AM

The quality of a good programmer is the ability to know how to beg borrow and steal the right code - AND when not to try and solve a problem from scratch.

Interview of two candidates
Q Write a class to put these items in a linked list.

Candidate 1 Wrote a nice linked list class and used it - failed
Candidate 2 Derived class from a library linked list class, and used sample code - Got job and went down to pub to celebrate!

Bob on February 28, 2007 2:35 AM

Having interviewed many so called developers I have come to the conclusion that programming is not necessarily judged *just* on technical skill, but on aptitude.

If an interviewee can show understanding of loops\variables\recursion in pseudo code, they can be taught the implementation in a given language in a few sessions - I normally take time out to teach any new developer coding standards anyway.

Have enjoyed seeing FizzBuzz in obscure languages, here's my contribution in VFP\Foxpro code:

FOR intLoop = 1 TO 100

? IIF(MOD(intLoop,15)=0,"FizzBuzz", ;
IIF(MOD(intLoop,5)=0,"Buzz", ;
IIF(MOD(intLoop,3)=0,"Fizz", ;
intLoop)))

NEXT

Lee on February 28, 2007 2:38 AM

//define your own output method with TRACE
void fizzbuzz(int i = 1)
{
if (i 100) return;
(i%15)?(i%3)?(i%5)?TRACE("%d",i):TRACE("Buzz"):TRACE("Fizz"):TRACE("FizzBuzz");
TRACE("\n");
fizzbuzz(++i);
}
void main()
{
fizzbuzz();
}
//yep, I know this kinf of code is a nightmare for thos who will mantain this code later ;)

Rouslan Grabar on February 28, 2007 2:46 AM

Nick Franceschina,the very best:))))

Cira on February 28, 2007 2:57 AM

Dim i As Integer = 1
Dim newline = False

For i = 1 To 100
Response.Write("br/")
If (i Mod 3 = 0) Then
Response.Write("Fizz")
End If

If (i Mod 5 = 0) Then
Response.Write("Buzz")
ElseIf (i Mod 3 0 And i Mod 5 0) Then
Response.Write(i)
End If
Next
End Sub

J on February 28, 2007 3:13 AM

My version starts with "copy con fizzbuzz.com" but it doesn't seem to be x-platform, so I'll refrain from posting it.

Gabri van Lee on February 28, 2007 3:32 AM

I still liked my version in C using one mod operation (i % 15) and a switch statement instead of ifs and elses.

Brendan Dowling on February 28, 2007 3:34 AM

I'm sure we've beat this thing to death, but here ya go perl fans:
for (1..100) {print $_ unless (($_ % 3 ? 0 : print "Bizz") || ($_ % 5 ? 0 : print "Fuzz"));}

This blog generated some comments on ISCA BBS, so figured we'd all take a crack at it in our preferred (and not-so-preferred) languages.

Figured I'd post this for perl folks to enjoy. Didn't realize b4 nesting in unless statements was possible like that, but hey...how often are we writing obfuscated code people have to think about to understand? Kind of pointless unless we are trying to tell all the other coders....gee I'm so much l337 than you, you're pathetic (which one wouldn't due in a professional shop anyway).

Jimmy Crackcorn on February 28, 2007 3:37 AM

for (int i=0;i101 ;i++)
{
System.out.println((i%3==0)?((i%5==0)?"fizzbuzz":"fizz"):(i%5==0)?"buzz":i+"");
}


programmers are idiots.

varen on February 28, 2007 3:41 AM

I prefer to ask why can't programmers program tests?

Unit tests are a great test of a programmer/developers skill and I think they should be a requirement for anyone in the modern age.

Owen on February 28, 2007 3:42 AM

PHP:

while(++$i101) {
if(!($i%15)) echo "FizzBuzz\n";
else if(!($i%3)) echo "Fizz\n";
else if(!($i%5)) echo "Buzz\n";
else echo "$i\n"
}

PHP on February 28, 2007 3:44 AM

"At Vertigo, we require a code sample before we even proceed to the phone interview stage."

I think that is a great idea !

The only thing better would be if the company was required to provide code samples to the interviewee .. you know, at a later stage in the process, perhaps right before offering a position.

One of the things I hate the most is going through an interview where I am grilled on the most obscure nuances of a language, the type of things you almost never encounter, only to find out after accepting the position that the developers at the company do NOT follow in reality what they preach in the interview.

David on February 28, 2007 3:54 AM

A proper XOR swap:

a = a ^ b;
b = a ^ b;
a = a ^ b;

Andrew Garber on February 28, 2007 3:55 AM

Why can half of the people here not seem to understand the specs of the prog. Remember its only to test dumb people :P

Mike on February 28, 2007 3:56 AM

Chris:
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.

Working without a mouse is a very unrealistic requirement. Unless your workplace is really out in the sticks, there is no real reason to go without a mouse for more than an hour.

Brady Kelly on February 28, 2007 4:00 AM

Welcome to school :)

For the VBScripters that were arguing over carriage returns, a CSscript solution in about 30 seconds:
Dim i
For i = 1 to 100
If i mod 3 = 0 Then WScript.StdOut.Write "Fizz"
If i mod 5 = 0 Then WScript.StdOut.Write "Buzz"
If CBool(i mod 3) And CBool(i Mod 5) Then WScript.StdOut.Write i
WScript.Echo ""
Next

Next we use VBScript to do it in ASP (ok, this is cheating :P ):
%
Option Explicit

Dim i
For i = 1 to 100
If i mod 3 = 0 Then Response.Write "Fizz"
If i mod 5 = 0 Then Response.Write "Buzz"
If CBool(i mod 3) And CBool(i Mod 5) Then Response.Write i
Response.Write "br/"
Next
%

Then something else...python?
a = []
for i in range(1,101):
a.append((i%15==0) and "FizzBuzz" or ((i%5==0) and "Buzz" or ((i%3==0) and "Fizz" or str(i))))
print a

Damn, time to take a shower and go to work. I think I just wasted most of my morning reading the other replies before I spent a couple minutes writing those three :P

Tarwn on February 28, 2007 4:03 AM

Another C# solution:

for (int i = 1; i = 100; i++) {
if (i % 3 == 0 || i % 5 == 0) {
if (i % 3 == 0) {
Console.Write("Fizz");
}
if (i % 5 == 0) {
Console.Write("Buzz");
}
}
else {
Console.Write(i.ToString());
}
Console.Write("\n");
}

Boris on February 28, 2007 4:10 AM

i'm sick of seeing C/C++ and other {} enclosed solutions so here's my VB6 version. spent less than 5 minutes on it, which is terrible going by other's standards.

dim num as byte, printstr as string
for num=1 to 100
printstr=""
if num mod 3 = 0 then printstr=printstr "Fizz"
if num mod 5 = 0 then printstr=printstr "Buzz"
if printstr"" then
debug.print printstr
else
debug.print num
end if
next

btw, i'm not proving myself. i'm 18, and i've already tried making a 2d game in VB6. oddly enough, it failed.

all this degrading of other applicants has made me want to apply for a programming job now! still at school for 3 months though.
God, i'm so arrogant.

Ninja the Nerd on February 28, 2007 4:20 AM

Just for the sake of perversity, here's a solution written as a Windows .BAT file:

@echo off

for /L %%I in (1,1,100) do call :FizzBuzz %%I
goto :EOF

:FizzBuzz
set I=%1
set /a T3=I %% 3
set /a T5=I %% 5
set /a T35=T3 + T5

if not %T35%==0 goto FizzBuzz5
echo FizzBuzz
goto :EOF

:FizzBuzz5
if not %T5%==0 goto FizzBuzz3
echo Buzz
goto :EOF

:FizzBuzz3
if not %T3%==0 goto FizzBuzzEcho
echo Fizz
goto :EOF

:FizzBuzzEcho
echo %I%
goto :EOF

Gary Wheeler on February 28, 2007 4:28 AM

In action Script ^^

for (var a:Number = 0; a100; a++) {
if (a%15 == 0) {
trace("Fizz-Buzz");
} else if (a%5 == 0) {
trace("Buzz");
} else if (a%3 == 0) {
trace("Fizz");
} else {
trace(a);
}
}

or

for (var a:Number = 0; a100; a++) {
trace(a%15 == 0 ? "Fizz-Buzz" : a%5 == 0 ? "Buzz" : a%3 == 0 ? "Fizz" : a);
}

nice lol ...

Bruno Leles on February 28, 2007 4:37 AM

I couldn't write down the matrix required for rotating a point in 3D space let alone solve the sine, cosine or other formulas that are plugged into that matrix. But I have written my own 3D game engine. I
can't show you on paper how to compute the distance between two latitude and longitude points, but I write map software for a package delivery company.

But how can that be? This is not trivial programming but according to the author of the article, I don't know how to program because I can't add in hex or solve a bitwise boolean operation in my head. I
argue that a good Software Engineer doesn't need to know how to solve these problems on a piece of paper. THAT IS WHAT COMPUTERS ARE FOR!

As a Software Engineer, problem solving skills are 80% of software engineering. The syntax of programming and programming well is the difference between a good programmer and a great programmer.

I don't need to know the mathematics for rotating a point in 3D space. But as a Software Engineer, I do need to know how to find that formula, how to implement it in code and where to use it.

I was passed over for a job because I couldn't "Write a function to compute the moving average of a stock price." Heck, I didn't even know what a "moving average" was. But when I got home I sat down and 20 minutes later I had a nifty little recursive function that answered the question. Why couldn't I do that in the interview? Because in the interview I didn't have the resources I would normally have while on the job. A good Software Engineer knows how to use those resources to solve programming problems.

I can't add in hex. And I really don't care...

Does that make me a bad programmer?

Bob on February 28, 2007 4:51 AM

It's so BASIC:

for i = 1 to 100
a$ = ""
IF i mod 3 = 0 THEN a$ = a$+"Fizz"
IF i mod 5 = 0 THEN a$ = a$+"Buzz"
IF a$="" THEN print i ELSE print a$
next i

30 seconds (but no PhD)

Tony the Ancient on February 28, 2007 4:52 AM

FWIW, I tried the sample code above using the XOR and OR and it didn't work for a=3 and b=5.

That use of the binary OR leads me to believe that it'll only work for powers of 2. (I.e., using | as a substitute for addition will only work as long as they don't both have the same bits lit up, as 3 and 5 do -- both use the first bit.)

I just tested with a=4 and b=16 and it worked. (Compiling with g++)

Is there a version of this that works with numbers that aren't powers of 2?

Drunkencop on February 28, 2007 4:55 AM

To the perl 1 liner author:
for (1..100) {print $_ unless (($_ % 3 ? 0 : print "Bizz") || ($_ % 5 ? 0 : print "Fuzz"));}

When you hit multiples of 3 and 5, it doesn't print BizzFuzz. Nice try though.

Ivan on February 28, 2007 4:58 AM

Here's my favorite implementation. It is better then everyone else's because it does not require a single modulo calculation! It can also fit on one line (a really long line!).

printf("1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\n10\n11\n .... Fizz\n100");


michael on February 28, 2007 4:59 AM

I think the problem is that you are hiring college graduates. Hire the natural self-taught talent! Having a CompSci college degree only means that they wasted 4 years (or more) of their lives. Whereas the self-taught programmers were busy writing software during those 4 years. And, why not test the interviewees on something more pragmatic, like create a business object that handles the CRUDs for s simple 3 or 4 property entity (or test them on something else that would be common for your company to write).

Nathan on February 28, 2007 5:05 AM

Thought I'd post a version in bash, just for kicks:

#!/bin/bash

TEST_DIVISOR_1=3
TEST_DIVISOR_2=5
UPPER_LIMIT=100

i=1
while [ $i -lt $(($UPPER_LIMIT+1)) ];
do
printed_text=0
if [ $(($i%$TEST_DIVISOR_1)) -eq 0 ]; then
echo -n "Fizz"
printed_text=1
fi
if [ $(($i%$TEST_DIVISOR_2)) -eq 0 ]; then
echo -n "Buzz"
printed_text=1
fi
if [ $printed_text -eq 0 ]; then
echo -n $i
fi
echo ""
i=$(($i+1))
done

d kinder on February 28, 2007 5:06 AM

Plain C:

int i;
for (i = 0; i = 100 ; i++) {
if ((i % 3 == 0) (i % 5 == 0))
printf("FizzBuzz\n");
else if (i % 3 == 0)
printf("Fizz\n");
else if (i % 5 == 0)
printf("Buzz\n");
else printf("%d\n", i);
}
I think that one word/number per line is more readable for such a useful piece of software... ;-)

YanG on February 28, 2007 5:09 AM

no one has done this one either ( I like the '?' operator). Its wonderfully confusing and only two statements:

for(int i=1;i=100;i++)
printf( !(i%3) || !(i%5) ? "%s\n": "%d\n",
!(i%3) !(i%5) ? "FizzBuzz":
!(i%3) ? "Fizz":
!(i%5) ? "Buzz":
i);

If you're system does not have modulo (oldschool!) or you're afraid that doing modulo may be a big performance problem (1khz clockspeed) here's a solution that requires only additions:

int m3 = 1;
int m5 = 1;
for(int i=1;i=100;i++) {
printf( !m3 || !m5 ? "%s\n": "%d\n",
!m3 !m5 ? "FizzBuzz":
!m3 ? "Fizz":
!m5 ? "Buzz":
i);
if(++m3 == 3)
m3 = 0;
if(++m5 == 5)
m5 = 0;
}

Or if you wanted to make the second half of the loop more complicated and wanted to get rid of all branching (only smart compilers would get rid of the branching), then you could do this:
m3 += (m3 == 2) ? -2 : 1;
m5 += (m3 == 4) ? -4 : 1;

michael on February 28, 2007 5:11 AM

I find there are a lot of people with the ability to memorize code and functions, but without the logical side to put it together. So if you ask what a certain does in PHP for instance, they'll be able to give you the definition. So in their mind the "know programming" but they don't know how to put the pieces together.

Tim Linden on February 28, 2007 5:19 AM

78 chars:

perl -le'print$_%15==0?"FizzBuff":$_%3==0?"Fizz":$_%5==0?"Buzz":$_ for 1..100'

Using naughty syntax we can get it down to 72 chars:

perl -le'print$_%15==0?FizzBuff:$_%3==0?Fizz:$_%5==0?Buzz:$_ for 1..100'

Here's the same program with sane indenting: http://rafb.net/p/QLtUvx47.html

example output:

1
2
Fizz
4
Buzz
Fizz
...
FizzBuff
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz
__END__

ua on February 28, 2007 5:20 AM

"90% of people can't touch one's elbow with one's tongue."
Hmm, can i?

for(int i=1;i=100;i++)
{
printf(i%3==0i%5==0?"fizzbuzz\n":(i%3==0?"fizz\n":(i%5==0?"buzz\n":"%d\n")),i);
}

Have a nice day!

Drmichi on February 28, 2007 5:21 AM

Love my old VB. Do it all backwards.

List1.Clear
Dim n As Integer, out As String
For n = 1 To 100
out = vbNullString
out = IIf(n Mod 3 = 0, "Fizz", vbNullString) + IIf(n Mod 5 = 0, "Buzz", vbNullString)
If out = vbNullString Then out = n
Call List1.AddItem(out)
Next

Edward on February 28, 2007 5:32 AM

Long live recreational QBasic programming!

FOR i = 1 TO 100
q = 0
p = 0
IF i / 3 = INT(i / 3) THEN
IF i / 5 = INT(i / 5) THEN
PRINT "FizzBuzz"
q = 1
END IF
IF q = 0 THEN PRINT "Fizz"
p = 1
END IF
IF i / 5 = INT(i / 5) THEN
IF p = 0 THEN PRINT "Buzz"
p = 1
END IF
IF p = 0 THEN PRINT i
NEXT i

***This is the stuff that real programming is made of!

[RANT]
I hate it when I see people learning Visual Basic. It's just so wrong. When I see people trying to figure out to throw an exception, I just shiver! It's like they miss the whole point of programming in the first place. The point of programming, FYI, is to make a function or group of functions which does something useful.

In my spare time I have created a few QBasic programs which do things like estimate the sine of a value from an infinite sum of square wave, calculate the power in the sine wave harmonics of a square wave, map points in 3d space to points in 2d space (like a graphics card), rotate a four-dimensional object, etc. I've also made (well mostly attempted to make) a few neural nets. This is all useful (or at least the type of stuff that could be useful). Making arrays defining functions are all useful things for everything I have done.

I don't see why exceptions are useful. They are just one of those unimportant, un-needed things that "programmers" learn about.

I personally like to handle every possibility personally in my programs and use deep thought to figure out how to map a particular set of inputs to the desired set of outputs. The VB programmers I know just don't seem to be that involved in what they are doing. They use VB like they would use Excel. Do you know what I'm saying?
[/RANT]

greeniguana00 on February 28, 2007 5:35 AM

For all of you self righteous geeks that started your FizzBuzz solutions at 0, your fired (or should I say, not hired) because you don't know how to follow instructions.

As for most of the others, the same! Your grammer and writing skills suck!

There is a lot more to programming than some clever implementation in a dozen different languages. How many of you really spent 30 minutes on your solution but claimed 4!

Michael, that is creative thinking. You're hired! (but if you ever do that in production code, I'll cut your balls off!)

Bob on February 28, 2007 5:37 AM

For the people that said the XOR trick would only work for integers... thats not entirely true...

It will work for characters as a single character in memory is really an integer in most languages. For strings you just have to break it down into a character array and use a loop (do/while looking for the null character '\0' at the end of the character array.

Also because of this, if you do actual memory swaps using this method it should be possible to do any other datatype/structure/object though you have to be using a language that will allow you to directly manage the memory.

And for the people that don't know the XOR trick (and can't look things up on Google..)
http://en.wikipedia.org/wiki/XOR_swap_algorithm

Kris on February 28, 2007 5:40 AM

Blazing fast LUT implementation by a coworker:

#include stdio.h

#define max 1000000

int main(void)
{
char X[250] = "%d \n%d \nfizz \n%d \nbuzz \nfizz \n%d \n%d \nfizz \nbuzz \n%d \nfizz \n%d \n%d \nfizzbuzz\n\0";
int modu = max % 15;
int full = max - modu;
unsigned int a;
for(a = 1; a full; a += 15)
printf(X, a, a + 1, a + 3, a + 6, a + 7, a + 10, a + 12, a + 13);
X[modu * 9] = 0;
printf(X, a, a + 1, a + 3, a + 6, a + 7, a + 10, a + 12, a + 13);
}

John on February 28, 2007 5:42 AM

on second thoughts

For n = 1 To 100
out = IIf(n Mod 3 = 0, "Fizz", vbNullString)
out = IIf(n Mod 5 = 0, out + "Buzz", out)
out = IIf(out = vbNullString, n, out)
Call List1.AddItem(out)
Next

is more consistent

Edward on February 28, 2007 5:43 AM

Oh, by the way, the max of one million was just for benchmarking purposes. Yes, we were comparing implementations...

John on February 28, 2007 5:52 AM

since you guys coded the solution to the FizzBuzz problem in most of the language and most of the language i know is C based so maybe i thought make an algorithm/pseudo code maybe that's where most new graduates failed to do or atleast imagine in their heads on how to come up with a solution.

1. start
2. declare variable named i
3. declare variables named x and y
4. set x to the remainder of i devided by 3
5. set y to the remainder of i devided by 5
6. if x and y equals to zero print the word FizzBuzz and jump to step 10 else jump to step 7
7. if x equals to zero print the word Fizz and jump to step 10 else jump to step 8
8. if y equals to zero print the word Buzz and jump to step 10 else jump to step 9
9. print the value of i
10. if i is less than or equal to 100 jump increment i by 1 and and jump to step 4 else jump to step 11
11. print the word "Done"
12. end

or at least master the flowchart in their head.

.::zanpakatou::. on February 28, 2007 5:54 AM

A recent job I applied for across the country (at the bequest of a friend who later was let go) involved a website with a programming test of ten or so questions of small to moderate difficulty. Most of them said 'in your choice of programming languages'.

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.

I was rejected out of hand because I didn't use one of the languages they had expected...or (probably more likely) understood. That was good enough for ME to know that I didn't want to be there. :)

Anyhow...just to add to the list: FizzBuzz in that language, a couple minutes of work, working the first time, with the (stated) assumption that each number's output will be on a separate line.

@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 ##

Jadawin on February 28, 2007 6:01 AM

Programmers cannot program .... because interviewers can't interview.

I think it's a matter of how easy it seems for a pretender to pass vs the chance to get caught. And obviously people think that it easy to pass an interview even it is not the right job for them (assuming they have a clue that they cannot fulfill the position). I just guess the passed in the past!
And what about the quality of testimonials from previous jobs?

Thomas on February 28, 2007 6:02 AM

Saw many implementation but no BASH script version, figured I'd include that:

#!/bin/bash

declare CNT=0

while [ $CNT -le 100 ]; do
[ $((CNT % 3)) -eq 0 ] echo -n "Fizz"
[ $((CNT % 5)) -eq 0 ] echo -n "Buzz"
[ $((CNT % 3)) -ne 0 -a $((CNT % 5)) -ne 0 ] echo -n $CNT
echo ""
CNT=$((CNT+1))
done

NickD on February 28, 2007 6:04 AM

I'm just leaning java.
more familiar with vb.vet
took 3 minutes - with all of that spent on
sorting out (still unfamiliar) if else {} syntax.

for (int i = 0; i = 100; i++) {
if (i % 3 == 0 i % 5 == 0)
System.out.println("fizzBuzz_3_5");
else if (i % 3 == 0)
System.out.println("fizz_3");
else if ( i % 5 == 0 )
System.out.println("buzz_5");
else
System.out.println(i);
}

mm on February 28, 2007 6:05 AM

Some of the problem has to do with college. A great many schools are selective because there is only a very limited type of student that the teachers will be able to educate. Most schools are ordeals of initiation, especially for undergrads, rather then places of learning. This is especially true for professions like medicine and law, where the real acquisition of knowledge starts at the post-graduate level.

I've had the Reverse Dumb-Ass Test Death Kick done to me. I took a course in number theory, went in to take the test, and had softball questions lobbed at me; better yet, I knew the answers to the questions!

Unfortunately, I wrote the numeral '1' with a serif on the bottom, and the professor insisted I wrote a '2'. Telling him I wrote a '1' did not change his mind.

Shortly after this experience, I decided that most universities are a waste of time, and decided to go learn things on my own.

Anonymous Cowherd on February 28, 2007 6:17 AM

To Toepopper,

Your interview question to swap the value of two variables with out using a temp variable is technically impossible. Just because you don't declare a temp variable, the operation a=a+b, uses a temp variable created on the fly. The operation b=a-b, uses a temp variable created on the fly. And the operation a=a-b, uses a temp variable created on the fly. In fact technically three temporary variables are created to perform these three operations...you just didn't declare them.

kcm on February 28, 2007 6:40 AM

Hmmm,
All this makes me wonder: "Why can't I find a decent programming job?" I can add in hex, and I thought up ways to write the fizzBuzz application in a plethora of different languages/methods.

And it makes me sad to think that this is the state that programming is in, and we wonder why we have software that doesn't work.

[sigh]

Luke on February 28, 2007 6:40 AM

But do they have COMMUNICATION/TEAMWORK skills? :/

Another MS SQL version - not elegant, but it works:
note: Begins and Ends not required but included for readability

declare @loopcount int

set @loopcount = 100

while (@loopcount 2)
begin
if @loopcount % 3 = 0
Begin
print 'Fizz' + cast(@loopcount as char)
End
else
if @loopcount % 5 = 0
Begin
print 'Bang' + cast(@loopcount as char)
End

if (@loopcount % 3 = 0 and @loopcount % 5 = 0)
Begin
print 'FizzBang' + cast(@loopcount as char)
End

set @loopcount = @loopcount -1
end

JLaw on February 28, 2007 6:41 AM

// Here's my attempt at an elegant C(++) solution.
// I'll assume the appropriate headers are included.
// This snippet can be put into main or elsewhere.
// I'm a bit rusty with the details, as I haven't
// C++'ed in years.

#DEFINE FACTOR0 3 // Using macros for easier portability to other
#DEFINE STRING0 "Fizz" // uses, without increasing code size, memory
#DEFINE FACTOR1 5 // needs, or decreasing performance.
#DEFINE STRING1 "Buzz"

for(int i=1; i=100; i++;)
{if(!(i%FACTOR0)) printf(STRING0);
elseif(!(i%FACTOR1)) printf(STRING1);
else printf("%i", i);
printf("\n");}

Blake Escritt on February 28, 2007 6:54 AM

I cann't resist... some people forget to print the number and another prints the number and the word... The requirements say: "Instead of the number print the word"

for (int i=0; i101; i++)
{
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
{
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 or 5... then print the number
{
cout i;
}
}
}
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 6:57 AM

Spencer asked "Does anyone have a link to more programming exercises that I could do?".

Check out www.projecteuler.net - The problems posted there require short programs but most also require a lot of thought. Depending on the language you use, you might have to borrow or write your own large integer class.

FredJ on February 28, 2007 7:03 AM

I think interview testing can be useful for both the employer and candidate. As a candidate for a job, I always give the following test to the employer. It is very simple:

What do the following acronyms stand for and if you get that far then give me a one-liner describing each:

SRP, OCP, DIP, LSP, ISP

If one or more of the technical people at the potential employer knows what these acronyms stand for and, even better, they know what they mean then I will consider working for them.

Never let the interviewer ask all of the hard questions.

Brian Keller on February 28, 2007 7:12 AM

You all have it wrong, the answer is simply:

System.out.println("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\".");

duh...

Me on February 28, 2007 7:13 AM

I welcomed Jeff's mention of FizzBuzz. As a novice (and I mean brand-spanking new) programmer being given a "challenge" like that is fun. Currently, I'm in college taking some programming courses. We're learning C# and ASP.NET. So I wrote my own little solution to FizzBuzz in C# via ASP.NET. Even though Jeff's remarks about developers "feverishly posting solutions" is funny, I rather liked seeing how others did it. I realize that with every problem there is more than one way to do it. What really got me confused was trying to figure out what language each poster was using.
Does anyone have a link to more programming exercises I could do? The exercises from the book aren't "real" enough. They ask me to create snippets of code that do something that really isn't useful, but it does test to see if I learned the topic from that chapter. I'd rather make something semi-useful rather than "Create a page in ASP.NET that displays a pop-up message when you click the button."
Thank you in advance.

Spencer on February 28, 2007 7:14 AM

DarkChucky - that won't work. The situation where it's a multiple of 3 AND 5 will fall into the first part of the if and never make it to the i%5==0 i%3==0 line. That check needs to be first.

Me2 on February 28, 2007 7:18 AM

Hey Stu,

It took me 13 years to get a 2 year degree in Data Processing (they didn't call it "Computer Science" back then). Can you infer my intelligence from that? Can you infer my programming skills from my failure to be able to add in hex?

Basically I am a self taught Software Engineer.

Today, I am an independent (currently writing map and delivery software). I charge $127.00 an hour. I have clients banging my door down. They are referred to me by previous clients because of the work I did for them.

So, to the employer who hired the geek, you probably made a good choice. But how many "great" choices did you pass up because they didn't pass your 'brain pan' test?

I still can't add in hex. And I still don't care...

Respectfully, laughing at your ignorance, all the way to the bank...

Bob on February 28, 2007 7:21 AM

My PHP version:
for ( $i = 1; $i = 100; $i++){
if ( $i % 3 == 0 ) $print = 'Fizz';
if ( $i % 5 == 0 ) $print .= 'Buzz';
if ( !isset($print) ) $print = $i;
echo $print.'br /';
unset($print);
}
Is clear and easy

Javier on February 28, 2007 7:29 AM

Now, what worries me is that I'm a designer and I could answer to the questions such as FizzBuzz and some dealing with recursion...

Janne on February 28, 2007 7:31 AM

pft..its really easy although time consuming. Thats why I can't see this as a way to test programmers skills... it took me like 30 minutes to solve this problem. each candidate * 30 minutes...figure it out!

anyway, here is my solution. (I had to use calculator after 25)

print 1
print 2
print "Fizz"
print 4
print "Buzz"
print "Fizz"
print 7
print 8
print "Fizz"
print "Buzz"
print 11
print "Fizz"
print 13
print 14
print "FizzBuzz"
print 16
print 17
print "Fizz"
print 19
print "Buzz"
print "Fizz"
print 22
print 23
print "Fizz"
print "Buzz"
print 26
print "Fizz"
print 28
print 29
print "FizzBuzz"
print 31
print 32
print "Fizz"
print 34
print "Buzz"
print "Fizz"
print 37
print 38
print "Fizz"
print "Buzz"
print 41
print "Fizz"
print 43
print 44
print "FizzBuzz"
print 46
print 47
print "Fizz"
print 49
print "Buzz"
print "Fizz"
print 52
print 53
print "Fizz"
print "Buzz"
print 56
print "Fizz"
print 58
print 59
print "FizzBuzz"
print 61
print 62
print "Fizz"
print 64
print "Buzz"
print "Fizz"
print 67
print 68
print "Fizz"
print "Buzz"
print 71
print "Fizz"
print 73
print 74
print "FizzBuzz"
print 76
print 77
print "Fizz"
print 79
print "Buzz"
print "Fizz"
print 82
print 83
print "Fizz"
print "Buzz"
print 86
print "Fizz"
print 88
print 89
print "FizzBuzz"
print 91
print 92
print "Fizz"
print 94
print "Buzz"
print "Fizz"
print 97
print 98
print "Fizz"
print "Buzz"

elijan sejic on February 28, 2007 7:35 AM

Method with one less if statement since 3 and 5 aren't mutually exclusive and variable names.

void main()
{
for (int i = 1; i = 100; i++)
{
bool isdiv3 = !(i % 3);
bool isdiv5 = !(i % 5);
if (isdiv3) cout "Fizz";
if (isdiv5) cout "Buzz";
if (!(isdiv3 || isdiv5)) cout i;
cout "\n";
}
}

Brandon on February 28, 2007 7:42 AM

«Back | More comments»

The comments to this entry are closed.