r/ProgrammerHumor • • Jan 16 '14

[deleted by user]

[removed]

1.3k Upvotes

446 comments sorted by

View all comments

149

u/novagenesis Jan 16 '14

What does an employer expect when they ask the FizzBuzz question in a way only completely unambiguous to someone who knows the FizzBuzz question?

Why not just say "hey, can you do fizzbuzz?"

132

u/Innominate8 Jan 16 '14

For someone who has no idea what fizzbuzz is, what this person did is not an unreasonable interpretation of the instructions. Technical interviews are often full of arbitrary seemingly unrelated questions brought on by interviewers who think they're being clever so it's hard to figure out what they actually want out of it.

It only looks stupid when you know what fizzbuzz is and fill the unwritten instructions in mentally. So in the end it's pretty much asking "Do you know what fizzbuzz is well enough to fill in the missing instructions?"

54

u/TheRingshifter Jan 16 '14

To be completely fair, this interpretation is the only reasonable interpretation of what the question asks... if you take it literally. If you write out some code on a piece of paper that code is never going to actually "print" anything. But writing the numbers out is printing them... the question should really just be worded:

"Write pseudocode (or java or whatever) which will ... [etc]"

It took me a good minute or two to figure out what he did wrong and I'm pretty sure I've heard of fizzbuzz at least in passing...

24

u/Xaquseg Jan 16 '14

Technically what's written there is already a form of pseudocode, I think the person writing the answer interpreted the question as "evaluate this pseudocode".

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.

→ More replies (6)

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.

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

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.

→ More replies (1)

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.

→ More replies (3)
→ More replies (4)

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)
→ More replies (4)

17

u/JBlitzen Jan 16 '14

Even knowing it, I see those instructions as deliberate, as if they want what he wrote.

That or they outsourced the instructions to some $1/hr elance dude in India.

If I were that company's owner, I'd be way more disappointed by the interviewer than the candidate.

2

u/ZarinaShenanigans Jan 17 '14

Or more accurately, "do you know how to apply modular arithmetic to a simple programming problem?"

→ More replies (6)