Hacker News new | ask | show | jobs
by Steve_Baker 5193 days ago
Every time fizzbuzz comes up, someone has to post a solution it seems, but why does everyone write such huge fizzbuzz programs?

  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);
3 comments

Some people value readability, some compactness / efficiency.

Why they do it one way or another is an occasionally interesting follow up question.

I'm in the readability camp, I'm one to comment my code even if it's something simple and I also like to use verbose variable names. I always keep in the back of my mind that if someone had to pick up my code without knowing how anything was implemented they might appreciate my efforts (even if it's just a personal project that I don't plan on anyone seeing). You can't please everyone I'm sure for as many people that like it compact there are people that like the whitespace.
A bit long, isn't it?

  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]

I posted it as a joke: http://www.codeslate.com/2007/01/you-dont-bury-survivors.htm...

However, yes it is huge it's Objective C with whitespace what do you expect? ;)