Yeah, honestly I had to come in to the comments to see why this was funny...I mean, I'm just learning to program and have obviously never had an interview, but were I presented with that piece of paper I wouldn't know what to do other than what the person in the picture did.
FizzBuzz is a common question asked by interviewers. The task is really easy and can be solved by good programmers in minutes, the purpose is only to filter out people who don’t have any clue of what they’re doing.
Generally, the task is: Write a program that prints the result shown in the image, but the instructions didn’t mention the "program" part, so OP read it literally and just wrote the expected result, as asked.
The task is really easy and can be solved by good programmers in minutes
The task is trivial and can be solved by bad programmers in minutes, it's literally intended to quickly exclude people who have no ability to program at all.
Amusingly, when presented to programmers in a web forum, a significant number of them take it as a challenge and quickly post implementations of it. More amusingly many of them are invariably wrong.
They worked in groups, they copied code from StackOverflow, they spent hours debugging simple errors, they learned programming to pass the course and then forgot about it immediately after.
Well anyone who's been to university knows that you can get through your courses purely through memorization.
If you go to the TA's enough, they will do bits of pieces and pieces each time, until the whole thing is solved. And there's usually enough questions that are exact copies of questions asked in class, and there's usually quite a few marks for memorizing the correct formulas and equations. For groupwork you can do the non-programming part of the work.
I think a year of university should be devoted to creating an independent final project. Students should be graded on code quality as well as project completeness/complexity. This would help weed out some of the memorizers.
Why get a job in programming then? Unless they plan to leach off their coworkers their whole life. As someone about to start a CS/CE dual major this fall and actually can program, i get a little angry when I hear things like this, because that problem is so simple that any idiot can solve it if they know any programming. That would be like a mathematician who can't do algebra.
That would be like a mathematician who can't do algebra.
That's precisely what it is, but the problem is it's very hard to evaluate a programmer before you hire them, especially when a lot of companies are nervous about asking them to actually program. Then it's very hard to fire them once you discover they actually can't program, so they stick around until you can finally get rid of them. But now they have experience they can tack on their resume and move on to the next job.
University doesn't even teach proper programming skills anyways. I haven't seen a program that has source control anywhere, code is rarely evaluated for clarity and style, and debugging isn't even taught. Half the people who graduate don't even know what a breakpoint is.
I was worried for a second reading this because this looks stupid easy. "But if it's an interview question it can't be that simple. Oh god I'm missing something. " etc. As I slowly doubt all my programming skills.
Python is pretty common for beginners, here's how to do it in that:
#Go from 0 to 100
for i in range(1, 101):
#Print Fizz if divisible by 3, print Buzz if divisible by 5, print the number if not divisible by either
print 'Fizz'*(not(i%3))+'Buzz'*(not(i%5)) or i
Ah true, here's that solution if anybody wants it:
#Go from 0 to 100
for n in range(1,101):
#Create an empty string to store output
output = ""
#Add Fizz to the output if number is divisible by 3
if not (n%3):
output += "Fizz"
#Add Buzz to the output if number is divisible by 3
if not (n%5):
output += "Buzz"
#Print output if input was divisible by 3 or 5 otherwise print input
print output or str(n)
This is extremely unpythonic and an ugly hack. It's ok for a quick script never to be used by anyone other than you, but bad code to demonstrate for a software engineering interview. From import this:
Simple is better than complex.
Sparse is better than dense.
Readability counts.
First, comments that lie are much worse than no comments at all. Your first comment lies; range(1,101) goes from 1 to 100 inclusive, not 0. Code that you don't need to comment is much cleaner than code that you need to comment. For a trivial piece of logic like this, don't mess it up by relying on python casting i%3 to a bool, applying not to it, and casting it back to an int type for string multiplication, as well as relying on or precedence being lower than string concatenation/multiplication.
for i in range(1, 101):
if i % 15 == 0:
print "FizzBuzz"
elif i % 3 == 0:
print "Fizz"
elif i % 5 == 0:
print "Buzz"
else:
print i
Not counting indentation/whitespace this clear obvious solution is 130 characters. Yours is 200 characters due to the terse code necessitating comments.
I've never been able to properly decide if python's typing is a great idea or an awful one.
When I'm not trying very hard, it's the perfect language; I give the computer simple, easy, logical instructions broken down to small chunks, and it does what I expect.
When I'm really on fire and in tune with the interpreter, I can give make the problem simplify into tiny, condensed snippets of code and basically solve itself.
When I think I'm on fire, but I'm really not paying attention, I end up doing something stupid and multiplying pointers all over the place and breaking everything. Those are the days that I curse under my breath and wish duck typing to be banished to wander the lost regions of the Sahara for a thousand years.
View all comments
Show parent comment
38
u/[deleted] Jan 16 '14
Yeah, honestly I had to come in to the comments to see why this was funny...I mean, I'm just learning to program and have obviously never had an interview, but were I presented with that piece of paper I wouldn't know what to do other than what the person in the picture did.