r/ProgrammerHumor • • Jan 16 '14

[deleted by user]

[removed]

1.3k Upvotes

446 comments sorted by

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.

20

u/danillonunes Jan 17 '14

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.

23

u/Innominate8 Jan 17 '14

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.

6

u/mirhagk Jan 17 '14

The task is trivial and can be solved by bad programmers in minutes

It's surprising just how many university graduates fail this. This problem has basically made me lose all faith in our education system.

7

u/[deleted] Jan 17 '14

Wait, there are people with degrees who can't write a few else-if statements? What the fuck did they do to get through college?

0

u/[deleted] Jan 17 '14

[deleted] — view deleted comment

5

u/blue_2501 Jan 17 '14

This. A college degree in computer science is like a college degree in car mechanics: Useless because experience matters much MUCH more.

I don't give a flying fuck that you spent 4 years pretending to program in Java.

3

u/kqr Jan 17 '14

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.

2

u/mirhagk Jan 17 '14

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.

2

u/[deleted] Jan 17 '14

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.

2

u/mirhagk Jan 18 '14

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.

→ More replies (1)
→ More replies (2)

3

u/takatori Jan 17 '14

ITT: hundreds of people trying to be clever by posting awkward solutions that they think are amusing and original.

2

u/weggles Jan 17 '14

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.

→ More replies (1)

1

u/[deleted] Jan 23 '14

I'm going to school for computer science and I aim to graduate at the end of 2015. Never interviewed for a programming job before.

I would be scared if graduates could not solve this problem.

9

u/acfman17 Jan 17 '14

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

22

u/[deleted] Jan 17 '14

That's a bit obtuse for beginners. I'd go with the if i%3 == 0: print('fizz'), etc. solution.

3

u/acfman17 Jan 17 '14

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)

23

u/djimbob Jan 17 '14 edited Jan 17 '14

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.

8

u/crazymuffin Jan 17 '14 edited Jan 17 '14

I like Java more.. example code, I bet there's thousand times better and simpler solution, but I'm, too a mere apprentice.

for (int i = 1;i<=100;i++) {
   boolean printed = false;
   if (i%3==0) {
      System.out.print("Fizz");
      printed = true;
   }
   if (i%5==0) {
      System.out.print("Buzz");
      printed = true;
   }
   if (!printed) {
      System.out.print(i);
   }
   System.out.print("\n");
}    

3

u/jdb12 Jan 17 '14

Dont do printlns. That way you can do the fizzbuzz automatically. Just have it do a blank println or print("\n") at the end of the function.

2

u/crazymuffin Jan 17 '14

Fixed. Drinking + coding = not a good idea :D

→ More replies (2)

1

u/acfman17 Jan 17 '14

I wanted to see how efficiently it can be done in Java and came across this. So complicated for such a simple problem lol.

public String fizzBuzz(int n){
  return (n>0) ? fizzBuzz(n-1) + 
(n % 15 != 0? n % 5 != 0? n % 3 != 0? (n+"") :"Fizz" : "Buzz" : "FizzBuzz"): "";
}
→ More replies (3)

15

u/BananaPotion Jan 17 '14

2hacky4me

0

u/[deleted] Jan 17 '14

[deleted] — view deleted comment

2

u/[deleted] Jan 17 '14

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.

→ More replies (2)
→ More replies (3)