FizzBuzz Test

feather240

New member
Jul 16, 2009
1,921
0
0
Apparently the majority of CS graduates don't even know how to program.

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.
Source: http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html

Note: Just because 99.5% of programmers are rejected doesn't mean that 99.5% of programmers can't program. People who are rejected constantly reapply for different jobs.




So members of the Escapist, can you solve the FizzBuzz problem? Which one of you can do it in the least amount of lines statements? Use this to post your code without losing indention marks http://pastebin.com/ (No registration required.), and then link you paste back here. If you've already posted an answer and want to contribute to the thread post a question.

Remember to use spoilers! [ spoiler ]DERP[/ spoiler ]

My Answer
No cheating.
Edit: Pastebin has a drop down menu called syntax. Use it to have your code highlighted.
 

evilneko

Fall in line!
Jun 16, 2011
2,218
49
53
This.. what... huh.... what is this I don't even....

I'm so utterly gobsmacked by this that words fail me.

And yet, despite my insistence that I am not a programmer, pseudocode for the fizzbuzz answer appeared pretty much instantly in my head. Translating that to actual code is pretty academic.

I mean, seriously?

I might could understand if it was something more advanced. I survived my second Java course by the skin of my teeth and copy-pasting bits from the professor's posted example programs and tinkering with them to make them work together (often, a homework assignment would be to do A, B, and C and he'd make separate example programs doing each one by itself, I don't think I started a single program from scratch in that class).

But really? Incrementing and outputting the value of a counter, except at particular values where you output something different? That's seriously intro-level stuff.

I can't even blame that on IDEs with IntelliSense and hand-holding error-highlighting (which is what I first thought about when reading the first few paragraphs). That's a flat-out logic failure right there. Introductory-level logic failure.

Granted I handwrite poorly so it'd probably take me longer than normal to write it by hand, but still. >.>
 

feather240

New member
Jul 16, 2009
1,921
0
0
evilneko said:
This.. what... huh.... what is this I don't even....

I'm so utterly gobsmacked by this that words fail me.

And yet, despite my insistence that I am not a programmer, pseudocode for the fizzbuzz answer appeared pretty much instantly in my head. Translating that to actual code is pretty academic.

I mean, seriously?

I might could understand if it was something more advanced. I survived my second Java course by the skin of my teeth and copy-pasting bits from the professor's posted example programs and tinkering with them to make them work together (often, a homework assignment would be to do A, B, and C and he'd make separate example programs doing each one by itself, I don't think I started a single program from scratch in that class).

But really? Incrementing and outputting the value of a counter, except at particular values where you output something different? That's seriously intro-level stuff.

I can't even blame that on IDEs with IntelliSense and hand-holding error-highlighting (which is what I first thought about when reading the first few paragraphs). That's a flat-out logic failure right there. Introductory-level logic failure.

Granted I handwrite poorly so it'd probably take me longer than normal to write it by hand, but still. >.>
I imagine that most students must be like this. http://www.smbc-comics.com/index.php?db=comics&id=2246#comic It would explain a lot.
 

evilneko

Fall in line!
Jun 16, 2011
2,218
49
53
Which is funny, considering that's exactly what I'm doing right now. (Well, okay, the test is tomorrow, but I have a superstition about studying immediately before a test) ;)

I just can't fathom how one can make it through multiple semesters of programming in various languages and not even accidentally pick up enough basics to know how to pass this FizzBuzz thing.
 

IsraelRocks

New member
Apr 21, 2010
352
0
0
cant believe i needed to look up how to write logic AND... although its been a year since i had a course involving C++. regardless my code is retarded after seeing your answer.


2nd year CS student here

the stuff the internet can make you do at 1 AM...

http://pastebin.com/234kUd5q
 

Not-here-anymore

In brightest day...
Nov 18, 2009
3,028
0
0
... I genuinely cannot program, and I'm pretty sure I could still do the fizzbuzz thing. In python, anyway. It's on my list of things to learn before term starts again. Seems you need it for university level physics.
 

LiberalSquirrel

Social Justice Squire
Jan 3, 2010
848
0
0
...What.

I mean, really. I know how to program an answer to that FizzBuzz thing. And I'm an English major. (Admittedly, a former engineering major, but still.)
 

Grabbin Keelz

New member
Jun 3, 2009
1,039
0
0
Wow, I could learn to program using internet tutorials and have a better chance at getting a computer job than most college graduates. I should go do that.
 

vrbtny

Elite Member
Sep 16, 2009
1,959
0
41
And there was me mistaking the title for Fizz-bin....

Dammit, suckered in....
 

Nocta-Aeterna

New member
Aug 3, 2009
709
0
0
OK, I can't write code to save my life, but I did a little amount of C not to long ago, so I can solve the FizzBuzz test with a combination of a do-while loop and a few if-else statements.
 

Alleged_Alec

New member
Sep 2, 2008
796
0
0
I have had two programming courses so far. I'm a biology major, and I could do AT LEAST FizzBuzz and the 1 tot 10 loop and depending on the program also the recurring problem. Hexadecimal could be a problem, but with a few minutes online, I could probably do that one as well.

What the hell is wrong with the (American???) schooling system if they cannot?


EDIT: My 1: AM in the morning, written while drunk AND in less than five minutes version:
http://pastebin.com/mJA83Vzf

Also: I used one of the least obvious (and slower) manners to solve this problem, because I didn't see this one yet, I think.

EDIT2: Hexadecimal solved as well using THE INTERNETZ!!!11oneoneone!

Protip: Conversion.Hex(int32) is your friend.

EDIT3: Even made one in my head using a fucking array. This is not difficult, people!
 

Esotera

New member
May 5, 2011
3,400
0
0
Two implementations in different languages - it's your lucky day. Took me about ten minutes, I failed at my javascript attempt, but I haven't actually learnt that yet. Also I haven't compiled/interpreted, so there might be a stupid error somewhere. If you see it let me know.

[link]http://pastebin.com/5Ynmrq0a[/link]

Programming education has always been poor. Learning about the theory can help, but the only way you'll learn is by doing it. Computer scientist =/= programmer. But it is shocking that some people don't know how to do a simple program like that after somehow passing a degree.

Out of interest, how long have programmers here been learning, and how many are self-taught? I've been going on and off for around a year and a half, and am entirely self-taught.

EDIT: Defeated on both implementations by forgetting that a number can be a multiple of 3 & 5..damn :(
 

Alleged_Alec

New member
Sep 2, 2008
796
0
0
Esotera said:
Two implementations in different languages - it's your lucky day. Took me about ten minutes, I failed at my javascript attempt, but I haven't actually learnt that yet. Also I haven't compiled/interpreted, so there might be a stupid error somewhere. If you see it let me know.

[link]http://pastebin.com/5Ynmrq0a[/link]

Programming education has always been poor. Learning about the theory can help, but the only way you'll learn is by doing it. Computer scientist =/= programmer. But it is shocking that some people don't know how to do a simple program like that after somehow passing a degree.

Out of interest, how long have programmers here been learning, and how many are self-taught? I've been going on and off for around a year and a half, and am entirely self-taught.

EDIT: Defeated on both implementations by forgetting that a number can be a multiple of 3 & 5..damn :(
You forgot to include the case it's a multiple of both five and three.

EDIT: Beaten by the edit -_-'
 

Esotera

New member
May 5, 2011
3,400
0
0
Alleged_Alec said:
Esotera said:
Two implementations in different languages - it's your lucky day. Took me about ten minutes, I failed at my javascript attempt, but I haven't actually learnt that yet. Also I haven't compiled/interpreted, so there might be a stupid error somewhere. If you see it let me know.

[link]http://pastebin.com/5Ynmrq0a[/link]

Programming education has always been poor. Learning about the theory can help, but the only way you'll learn is by doing it. Computer scientist =/= programmer. But it is shocking that some people don't know how to do a simple program like that after somehow passing a degree.

Out of interest, how long have programmers here been learning, and how many are self-taught? I've been going on and off for around a year and a half, and am entirely self-taught.

EDIT: Defeated on both implementations by forgetting that a number can be a multiple of 3 & 5..damn :(
You forgot to include the case it's a multiple of both five and three.

EDIT: Beaten by the edit -_-'
Yes, it's an infuriatingly simple mistake, which I'm going to attribute to my lack of sleep. For python line 7 needs changing to if, for C++ there's numerous ways to go about it.

Musiclly enhanced said:
wow im 15 and only looked at youtube tutorials and i could do this
Try it before saying that - it's deceptively hard. I've completed much harder problems than this but this one seems to throw a lot of people off.
 

Erana

New member
Feb 28, 2008
8,010
0
0
Esotera said:
Programming education has always been poor. Learning about the theory can help, but the only way you'll learn is by doing it. Computer scientist =/= programmer. But it is shocking that some people don't know how to do a simple program like that after somehow passing a degree.
But if you think that's bad, try being in an art major. Morons can get away with even less.
It makes the few students in the arts that actually give a damn look bad. I mean, just by admitting that I'm an art student, people question the validity of my education.

All those "I'm being an art major because its easy! :V" morons around, and I went to a good school. At least they got beat down in Senior year and were forced to produce something or fail. I can't imagine how little one could get by with in an average school...

But that's the thing. You don't have to be a good student in anything. Isn't the average graduating GPA required by most schools between 2.0 and 2.5? That's terrifying to me.
 

Musiclly enhanced

New member
Sep 8, 2010
150
0
0
Esotera said:
Alleged_Alec said:
Esotera said:
Two implementations in different languages - it's your lucky day. Took me about ten minutes, I failed at my javascript attempt, but I haven't actually learnt that yet. Also I haven't compiled/interpreted, so there might be a stupid error somewhere. If you see it let me know.

[link]http://pastebin.com/5Ynmrq0a[/link]

Programming education has always been poor. Learning about the theory can help, but the only way you'll learn is by doing it. Computer scientist =/= programmer. But it is shocking that some people don't know how to do a simple program like that after somehow passing a degree.

Out of interest, how long have programmers here been learning, and how many are self-taught? I've been going on and off for around a year and a half, and am entirely self-taught.

EDIT: Defeated on both implementations by forgetting that a number can be a multiple of 3 & 5..damn :(
You forgot to include the case it's a multiple of both five and three.

EDIT: Beaten by the edit -_-'
Yes, it's an infuriatingly simple mistake, which I'm going to attribute to my lack of sleep. For python line 7 needs changing to if, for C++ there's numerous ways to go about it.

Musiclly enhanced said:
wow im 15 and only looked at youtube tutorials and i could do this
Try it before saying that - it's deceptively hard. I've completed much harder problems than this but this one seems to throw a lot of people off.
sorry i googled what was in the test cs that is a nightmare wall of text and its late
 

feather240

New member
Jul 16, 2009
1,921
0
0
IsraelRocks said:
cant believe i needed to look up how to write logic AND... although its been a year since i had a course involving C++. regardless my code is retarded after seeing your answer.


2nd year CS student here

the stuff the internet can make you do at 1 AM...

http://pastebin.com/234kUd5q
Like how you put a quotation mark in the middle of your program and rendered half of it irrelevant?

Esotera said:
Musiclly enhanced said:
wow im 15 and only looked at youtube tutorials and i could do this
Try it before saying that - it's deceptively hard. I've completed much harder problems than this but this one seems to throw a lot of people off.
The issue isn't doing it wrong, it's not knowing where to start.
 

MidnightCat

New member
Jul 21, 2009
125
0
0
That's fine, it just means there'll be more programming positions available for me to choose from.

Using C++ [http://pastebin.com/JVS6NdHR] // Using Java [http://pastebin.com/rYAG0LSi]