Pertinent passage: FizzBuzz was presented as the lowest level of comprehension required to illustrate adequacy. There's no glory to be had in writing code that establishes a minimum level of competency. Even if you can write it in five different languages or in under 50 bytes of code.
for(int i=1; i <= 100; i++)
printf((char *[]){"%d\n","Buzz\n","Fizz\n","FizzBuzz\n"}[((i%3==0)<<1)|((i%5)==0)], i);Why they do it one way or another is an occasionally interesting follow up question.
1_,`0:'{:[~x!15;"FizzBuzz";~x!3;"Fizz";~x!5;"Buzz";$x],"\n"}'1+!100
(Thats https://github.com/kevinlawler/kona)[Edit: Found a way to shave off three chars]
However, yes it is huge it's Objective C with whitespace what do you expect? ;)
Does it work is the most important thing by a mile but if you've asked them to wrie production ready code then you've got to ask "how would I feel if one of my developers checked this into version control and how would it fair in a code review?"
Maintainability, readability, efficiency and most significantly the candidates ability to explain why they took the approach they did.
I wouldn't hold any approach against someone so long as they could talk intelligently about the trade offs and why they'd done what they'd done.
Even really simple problems are a chance to see whether someone thinks about things.
Your comment supposes that the loop will increment without interference. While you'd hope that was the case, it's not necessarily true.
Obviously with the loop as coded your comment is correct (that'll be the first condition that terminates the loop) but it could raise a question about whether comments should reflect the routine as written or just the section they're immediately referring to.
Or indeed whether comments for something so self evident are even useful or necessary... Something I'd definitely ask in an interview if I was presented with this code, not looking for a specific answer, just looking for some indication that the candidate had (or could come up with) some vaguely informed thoughts on the subject.
-(void)fizzbuzz { int i = 1;int t = 3; int f = 5;int h = 101; int z = 0;