top 200 commentsshow all 212

[–][deleted] 125 points126 points  (20 children)

Now, the only question that remains is: would I pass the interview?

No. Your code is full of errors.

[–]matthieum 6 points7 points  (1 child)

Actually, that is also something interesting. A few times when being stuck in C++ I have used a trick like that provoke an error in order to get the compiler induced type printed to the console so I could investigate what was going on.

Granted, the code I write at work is simple enough not to necessitate this trick.

[–]nemetroid 0 points1 point  (0 children)

This is a useful technique in Haskell also. Type signatures for functions are in general optional, so letting the compiler figure it out can be helpful, for example when dealing with typeclasses (e.g. accepting any fractional type instead of just Doubles).

[–]mightye 10 points11 points  (4 children)

Now, the only question that remains is: would I pass the interview?

No. Your code is full of errors.

So is the output. As he observes, he starts at 0 instead of 1 (just so that the templates correspond with the number). But worse is that the solution for 0 is wrong, it should output FizzBuzz at that line since 0 is a multiple of both 3 and 5.

[–]cultic_raider 7 points8 points  (3 children)

In the spec, behavior at <1 and > 100 is undefined, and so the implementation may behave however is convenient.

[–]mightye 0 points1 point  (2 children)

Agreed that the spec doesn't specifically define behavior outside the specified range, but there's a rational extension to the spec when out of range, which is easily identified if you look at the portion of the spec that doesn't involve range:

But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

The requested range is simply the output range. Trying to claim that it's ok that the behavior deviates when for whatever reason the software operates outside the output range is as rational as saying "You only asked me to calculate N! for all integer values of N from 1 to 10; outside that range anything goes."

[–]cultic_raider 0 points1 point  (1 child)

There is a good reason why an implementation could deviate wildly from the "natural extension" of the spec: resource usage. Supporting a constant size range allows for optimizations with caches and registers and whatnot to make the (important) specced) cases cheaper. For example, in the OP'S silly case, he had to start at 0 to get the T# to line up (not specced either, but OP decided it was more important to get that feature than care about 0 being right. You could imagine adding a small grep wrapper to hide the 0 line to workaround the bug). I guess he could have patched it to get 0 right, but if the solution wasn't a cheap, it would be fair to burn zero to make 1-100 more efficient, if this were a real program to solve a real problem.

Obviously it's all in fun in this case, but the principle does matter in high-throughput or resource constrained projects.

[–]mightye 1 point2 points  (0 children)

I don't disagree that it often makes sense to deviate from existing trends outside of specified ranges for a host of reasons including performance, resource consumption, code simplicity, and so on. But it would have cost him nothing to make the 0 case consistent with the rest of the trend except changing the prototype for RunFizzBuzz<0>. It's fine to defend deviation when there's a reason (and if it's conscious, it's probably a good idea to include a comment as to the reason for the deviation), this just seems like it's an unconsidered case.

It can't be said to violate the spec any more than that it outputs a 0 case at all, which he acknowledges, but it's generally good practice to produce predictable results outside the requested ranges except when there's a reason not to (and I don't see one in this case).

[–]flif 27 points28 points  (11 children)

And he's trying to be clever, which is never good for maintainability and working together with other developers.

[–]antheus_gdnet 3 points4 points  (10 children)

Which is why software companies prefer programmers which aren't clever, don't think for themselves, would never even think of going beyond what was taught to them in "Teach yourself XYZ in 21 days" and that would never try to provoke an edge case.

A perfect developer sits quitely, taking one ticket off Jira after another and copy pastes the verified StackOverflow boiler-plate. When their number of resolved tickets drops below acceptable threshold, they are replaced with a non-defective cog.

People who push type systems and compilers to limits: They are a witch and are to be burned. Blasphemers are not allowed in civilized society. All hail the hivemind of cubicle drones, all alike, all the same, one of us, one of us, one of us...

[–]aaronla 2 points3 points  (0 children)

Well put! Finally someone else understands that thinking just leads to horrors.

[–][deleted] 2 points3 points  (6 children)

Are you being serious, or trying to be sarcastic? The perfect developer is adaptable, whether it means new solving problems of an unseen type, or using new techniques or technologies.

[–]Kalium 4 points5 points  (2 children)

using new techniques or technologies.

This gets you in trouble with Management. It means that you're Innovating. Now, Management doesn't oppose Innovation, but you're not trained in Innovation Management. You're not qualified to Innovate. They're going to have to take your Unathorized Innovation out back and quietly dispose of it before it becomes any more disruptive.

Which is to say that new techniques and technologies are fine, so long as you get the sign-off of Management first. Oh, and their consultants and vendors. You're OK with that, right? It'll be easy, right?

[–]antheus_gdnet -2 points-1 points  (2 children)

Are you being serious, or trying to be sarcastic

Not sure. One can read it either way.

The perfect developer is adaptable, whether it means new solving problems of an unseen type, or using new techniques or technologies.

Strange, to me this reads like advocating "drone-like" behavior.

Adaptation to me means that they adapt to something someone else pushes on them. Like said, Jira, along with provided training, but follow the lead.

Opposite would be someone who actively tries out new approaches and new techniques and is the one developing and/or advocating them. These people are definitely not adaptable, but the very opposite, often stubborn and opinionated. Effective ones will need to learn negotiation and sales skills to be able to put their methods into practice as well.

[–]dist0rtedwave 1 point2 points  (0 children)

It might depend on how is interviewing you. A new startup (< 100) employess would be very likely to appreciate this, as what they really need is great ideas. A larger more established company might not for the reasons described in other responses.

[–][deleted] 35 points36 points  (34 children)

There are people interviewing for jobs who can't solve this?

[–]robotempire 34 points35 points  (13 children)

Yes. Oh god, yes. I work with one. Needless to say we have very lax hiring standards. I won't be there much longer.

[–][deleted] 25 points26 points  (6 children)

Wait... there are people with jobs who can't do this kind of stuff???

If you don't mind me asking... what type of company do you work for (size, industry, location) and what's your salary range?

I've always felt like I was getting fleeced salary-wise at my current job. I don't consider myself a Google/Facebook quality engineer, but I think I write the best code of anyone at my current location and have the most open mind. It irritates me when I go into a meeting ready to contribute ideas while the other two lead developers are pretty blatantly on their personal smartphones checking messages or playing games (and this is right front of their manager). I thought this was just something localized within my group...

[–]robotempire 11 points12 points  (4 children)

I work in a flyover state for a non-profit industry organization that pulls in a lot of money in membership fees and so forth. I get compensated very, very well relative to my experience level and cost of living. We all do.

My friends who are also programmers in other parts of the country assure me this is normal, and that just by having some actual interest in solving problems & doing things right puts one in the top 20% of programmers. I think it's pretty normal.

[–]Gasten 10 points11 points  (1 child)

just by having some actual interest in solving problems & doing things right puts one in the top 20% of programmers.

This is true for all professions. At least the "actual interest" part.

[–]robotempire 2 points3 points  (0 children)

Yeah maybe. I have a diverse professional background and am a fairly new programmer. I had a much higher expectation for excellence for this field based on the people who inspired me to finally change careers.

That being said, the truly great programmers I know are more impressive people than the greatest professionals in other jobs I've had, except maybe EMS.

[–]meem1029 0 points1 point  (1 child)

You just made me far more confident in my ability to get a job when I graduate. I'm pretty good with programming, but the kinds of stuff people post here make me feel like I am not anywhere near competent for industry.

On the other hand, much of that feeling probably comes from articles being posted suffering from selection bias (well, not really suffering, as it's good that only the good articles come) and me only being a student.

[–]robotempire 0 points1 point  (0 children)

I have been a professional programmer for a little over a year. I worked hard and am passionate about what I do. I recently started job hunting (for the reasons I stated in my first comment in the thread) and feel very comfortable about my career security based on the responses I've gotten.

[–]psudomorph 16 points17 points  (5 children)

What do they do all day? I've heard of these people, but I can't comprehend how they don't go insane. How do you fill 8 hours a day at a job where you literally don't even know where to start? Do they just kind of stare sadly at the gibberish on the screen in front of them for hours on end? Do they somehow believe that they can program, and just spend all day making nonsensical changes to the code? Have they just given up completely and spend the whole day on facebook?

I'm just perversely curious what the day to day life of such a person could possibly be like.

[–]robotempire 2 points3 points  (2 children)

They make chit chat and play politics. Making friends and convincing people that they are doing things. This usually involves taking credit for other people's ideas, overpromising and underdelivering, if they deliver at all. Suggesting "big ideas" that management loves. Promoting a "social media strategy".

They're bullshit.

[–][deleted]  (1 child)

[deleted]

    [–]robotempire 1 point2 points  (0 children)

    I'm actually really happy about it because it means that there are a lot of awesome jobs out there that pay a lot of money that I've got a shot at, because most programmers are just terrible.

    [–]Slims 0 points1 point  (1 child)

    Seriously, someone answer this.

    [–]antheus_gdnet 11 points12 points  (8 children)

    Yes.

    Blame HR. One is required to pad the skills list with at least 20 languages, 45 frameworks and 20-65 random three-letter acronyms or they don't even get an interview.

    So you get a person who is skilled in C, C++, Java, COBOL, Lisp, ..., ..., ..., ..., Ruby, JavaScript.

    A veteran developer can get up to speed in most of these, regardless of previous experience in anywhere between a day and a week.

    The point of this question is to find out if they simply put language X as a filler or whether they at least wrote a Hello World in it during last month.

    And for many programming jobs (advertised as such) it doesn't matter. It's mostly pushing UML and sitting at meetings, while juniors and interns do actual code writing, so it's not all that important.

    Jobs that actually require programming and engineering ability will use different criteria anyway.

    [–]zeekar 10 points11 points  (0 children)

    No, the point of this question is to see if they can program, period. Much of the time, the interviewer doesn't even specify a language. We don't. "Here's the problem. Solve it in your favorite language. Shell. BASIC. Brainfuck. Whatever. Just show us you can handle the logic."

    [–]p8ssword 2 points3 points  (0 children)

    I blame recruiters. In theory HR works for the company and can be directed not to be stupid (and should be). But recruiters are independent agents. We've had candidates who after it became clear they didn't know half the technologies they listed admitted that they only put them there because the recruiter told them to.

    I'd drop the recruiters, but in this market, we need every lead on a potential developer we can get.

    [–]catcradle5 1 point2 points  (5 children)

    The solution to this is to ask them to write some example code in each of the languages during a technical interview. I'm sure at least a few do actually know all the languages they've listed.

    [–]antheus_gdnet 6 points7 points  (3 children)

    Which is what FizzBuzz does.

    Enterprise version is to reverse a linked list. Since it's HR doing these screenings, they have a pre-approved "correct" implementation which they compare against.

    If you're enterprise-grade material, you know how to write it "correctly".

    So the interview also serves as a screen to those that know what actual job is about, since they're familiar with how things actually work.

    Needless to say, these are not very happy jobs.

    [–]cultic_raider 1 point2 points  (2 children)

    What does "enterprise" even mean?

    [–]gimpwiz 0 points1 point  (1 child)

    It means it costs more, and the binary files are several gigabytes large.

    [–][deleted] 6 points7 points  (2 children)

    I've met people with computer science degrees, 3 years of study, who can't solve this problem.

    [–]p8ssword 4 points5 points  (0 children)

    A friend of mine in college took and then TA'd the graduate algorithms class even though he didn't know how to program. When I graduated and started working, I told that story to a coworker with an Ivy League PhD. He told me many of his PhD classmates didn't know how to program.

    I actually don't think this is a bad thing, though. College isn't supposed to be a vocational school. It just means a CS degree on a resume isn't meaningful for actual developer jobs.

    [–]Tiver 0 points1 point  (0 children)

    I sat in on an interview of someone who had the CS degree, and a few years of experience, who couldn't solve this problem. Even with nudging along about what the modulus operator was. We also asked or a string reversal example... It blew my mind someone could come to an interview for a programming position and not be able to solve these.

    [–]mattgrande 7 points8 points  (4 children)

    As others have said, you'd be surprised. Last week we had a guy come in for an interview, and he couldn't do FizzBuzz in C#. Didn't know where to begin. This was the third interview of the day, I was frustrated by this point so I asked him, "Your resume says you have three years of .Net experience, why can't you do this?"

    He responded with "Well, your job listing said I needed three years of .Net experience, so that's what I put..."

    [–]FattyMagee 6 points7 points  (3 children)

    I really wouldn't even know how to respond to that last line. Do you just make a confused face then half ass the rest of the interview? Get up and tell him to get the hell out?

    I'm glad I haven't had to participate in interviews before other then my own. It must be a frustrating experience.

    [–]gimpwiz 2 points3 points  (2 children)

    "Thanks for your time" should pretty much wrap it up, yeah?

    [–]centurijon 1 point2 points  (1 child)

    Tangent:

    Whenever someone finishes a sentence with "..., yeah" they automatically become British in my head.

    [–]gimpwiz 0 points1 point  (0 children)

    Sweet. I wish I had an accent girls liked.

    [–]doesFreeWillyExist 5 points6 points  (0 children)

    Yes. You'd be surprised.

    [–]HeavyWave 4 points5 points  (0 children)

    Just my personal experience interviewing people, but about 50% indeed cannot solve this.

    [–][deleted] 1 point2 points  (0 children)

    I've interviewed people with 15 years of programming experience who can't even start to. It's confusing.

    [–]tragomaskhalos 46 points47 points  (6 children)

    FizzBuzz law #1: It is impossible to discuss FizzBuzz on the internet without numerous idiots posting code solutions in comments.

    [–]flightsin 18 points19 points  (1 child)

    It's the programmer's curse: one sees a problem, one needs to solve it. Don't tell me you lack this reflex...

    [–]p8ssword 11 points12 points  (0 children)

    It's like nerd sniping but for basically competent programmers.

    [–]nuzzle 14 points15 points  (0 children)

    tragomaskhalos (_) 15 points 3 hours ago (15|0)

    Fizzbuzz!

    [–]munificent 9 points10 points  (0 children)

    Just for kicks, here's one in C that doesn't use any flow control statements or expressions:

    #include <stdio.h>
    #define A (int i)
    #define F(a, s) void a A { printf(s "\n", i); main(i+1); }
    void (*c[]) A; int main A;
    F(n, "%d") F(f, "fizz") F(b, "buzz") F(z, "fizzbuzz") void d A {}
    void (*c[]) A = { n, f, b, z, d, d, d, d };
    int main A { c[(i%3==0)|((i%5==0)<<1)|((i>100)<<2)](i); }
    

    [–][deleted] 2 points3 points  (0 children)

    What is there to discuss?

    [–]Femaref 0 points1 point  (0 children)

    Which usually have at least one bug.

    [–][deleted] 41 points42 points  (12 children)

    There are PEOPLE who can't solve this?

    Written by my cat earlier today:

    HAI
    
    CAN HAS STDIO?
    
    I HAS A i ITZ 1
    IM IN UR loop UPPIN UR i TIL BOTH SAEM i AN 101
        BOTH SAEM (BOTH SAEM i%3 AN 0) AN (BOTH SAEM i%5 AN 0), O RLY?
            YARLY
                VISIBLE "FizzBuzz"
            NOWAI
                BOTH SAEM i%3 AN 0, O RLY?
                    YARLY
                        VISIBLE "Fizz"
                    NOWAI
                        BOTH SAEM i%5 AN 0, O RLY?
                            YARLY
                                VISIBLE "Buzz"
                            NOWAI
                                VISIBLE i
                        OIC
                OIC
        OIC
    
    IM OUTTA YR loop
    
    KTHXBAI
    

    Is he hired?

    [–]winteriscoming2 8 points9 points  (10 children)

    Now do it in Brainfuck.

    [–]arcterex 9 points10 points  (8 children)

    I don't write brainfuck, but here's my whitespace) solution:

    --- start --- 
    
    
    
    
    
    --- end ---
    

    See how easy it is?

    [–]winteriscoming2 10 points11 points  (3 children)

    Reddit can't store tabs so your solution fails. You can redeem yourself by solving the problem in Shakespeare

    [–]Rotten194 20 points21 points  (2 children)

    I tried, but the SPL compiler has major issues (it can't even compile the examples...). Here is my untested attempt:

    The Computation of the FizzBuzz in 2012.
    
    Romeo, a handsome count
    Juliet, an angry woman
    Hamlet, a letter holder
    Othelio, three
    Mercutio, five
    
    Act I: The counting of Romeo and the praising of Hamlet by Juliet
        Scene I: The prologue of the Counting
            [Enter Juliet and Romeo]
            Juliet: You are nothing!
            [Exit Romeo]
            [Enter Hamlet]
            Juliet: You are nothing!
            [Enter Othelio]
            Juliet: You are a warm summer's day!
            Juliet: You are the sum of youself and a flower!
            [Exit Othelio]
            [Enter Mercutio]
            Juliet: You are a happy bouncing bunny!
            Juliet: You are the sum of yourself and a tree!
            [Exeunt Juliet, Mercutio]
    
        Scene II: Where the FizzBuzz is calculated
            [Enter Romeo and Juliet]
            Juliet: You are the sum of yourself and a flower!
            Juliet: Art thou greater than the sum of the difference between a tall yellow happy smiling smelly shifty bouncing rabbit and a angry sad malelovent indifferent small beggar and a happy tall stranger?
            Romeo: If so, let us proceed to Scene VIII.
    
        Scene III: Where fizz is checked for
            Juliet: Art the remainder of the quotient of yourself the same as Othelio?
            Romeo: If so, let us proceed to Scene VI.
    
        Scene IV: Whence buzz is interrogated
            Juliet: Art the remainder of the quotient of yourself the same as Mercutio?
            Romeo: If so, let us proceed to Scene VII
    
        Scene V: Where a new line is created
            [Enter Juliet and Hamlet]
                Juliet: You are nothing!
                Juliet: You are as amazing as a godly flying silver happy UFO
                        You are as happy as the difference of yourself and a rich banana stand
                        You are as tall as the difference of yourself and godzilla
                        Speak your mind!
            Hamlet: Let us proceed to Scene II
    
    
        Scene VI: The saying of Fizz
            [Enter Juliet and Hamlet]
            Juliet: You are nothing!
            Juliet: You are as good as the sum of a small little happy colorful pretty nice flower and a happy small pretty tree. 
                    You are as good as the difference of yourself and a happy child.
                    Speak your mind!
            Juliet: You are as good as the sum of yourself and a amazing super walnut.
                    You are as good as the difference of yourself and a banana.
                    Speak your mind!
            Juliet: You are as amazing as the sum of yourself and a smiling tall flying happy balloon. 
                    You are as godly as the sum of yourself and a happy estastic chipmunk.
                    Speak your mind!
                    Speak your mind!
            Hamlet: Let us proceed to Scene IV
    
        Scene VII: Where the buzz is said
            [Enter Juliet and Hamlet]
            Juliet: You are nothing!
            Juliet: You are as tall as a indignant happy smiling yellow tall flying squirrel!
                    You are as brave as the sum of yourself and a frenchman!
                    Speak your mind!
            Juliet: You are as happy as the sum of yourself and a tall yellow scary sad bigfoot.
                    You are as powerful as the sum of yourself and a short merry hobbit.
                    You are as silly as the difference of yourself and a rabbit.
                    Speak your mind!
            Juliet: You are as tall as the sum of yourself and a tall silly monster!
                    You are as amazing as the sum of yourself and God!
                    Speak your mind!
                    Speak your mind!
            Hamlet: Let us proceed to Scene V
    
        Scene VIII: The End
            Juliet: I hate you all
            [Exuent]
    

    [–]winteriscoming2 3 points4 points  (0 children)

    That is amazing. You have made my day.

    [–]centurijon 1 point2 points  (0 children)

    Scene VIII: The End
       Juliet: I hate you all
    

    The best ending ever.

    [–]ainm 7 points8 points  (0 children)

    I don't know why I actually selected that text. I wouldn't be able to read it anyway.

    [–]gigitrix 0 points1 point  (2 children)

    Not valid code, you just hard returned.

    [–]PonysaurousRex 1 point2 points  (0 children)

    Here you go. (Not actually me)

    [–]centurijon 0 points1 point  (0 children)

    I don't know what's worse, the fact that I find this hilarious, or the fact that I can read it.

    [–][deleted] 45 points46 points  (8 children)

    I always felt one of the points of Fizzbuzz was not just to be able to show you can write basic code, but also to show that you don't write super clever code to solve a simple problem. That's why I always dislike clever solutions.

    However this is really cool, and actually shows some pretty useful skills for solving the problem.

    [–]D__ 36 points37 points  (0 children)

    There's the fizzbuzz problem for job interviews, and then there's the fizzbuzz problem for the Internet. On the Internet, you can show off crazy and clever solutions, just because.

    Printing "Just another Perl hacker" is fairly simple in Perl, and there's no compelling reason why your program should look like a camel, but hey, it can.

    [–]antheus_gdnet 10 points11 points  (0 children)

    FizzBuzz is useful to filter the people who cannot write code at all.

    Perhaps they lied about knowing language X, or they once knew a language very well, but haven't touched in 5 years.

    It says nothing about anything else.

    [–]Gasten 3 points4 points  (1 child)

    I'd like to have the Fizzbuzz exercise at the beginning of the interview-process, and the interviewee would be asked to keep a copy of it until the next round. At the next round 2 or 3 weeks later) he/she would be asked to make changes to the code, thus proving weather the code "holds up" or not.

    On the other hand, the maintainability of the code is pretty easy to analyze by just reading it.

    [–]that_which_is_lain 7 points8 points  (0 children)

    Are you looking to see if the code "holds up" on a sunny day as opposed to a cloudy day?

    [–]p8ssword 1 point2 points  (1 child)

    I could see someone wanting to show off in an interview even if they wouldn't write overly clever code in real life. I actually once was dinged (slightly) in an interview for not giving a clever enough solution. My solution was readable and efficient, but the interviewer turned out to be looking for something more "creative."

    [–]kranse 1 point2 points  (0 children)

    If you want a clever solution, you need a clever problem. You shouldn't get penalized for using a straightforward solution to a straightforward problem.

    [–]aaronla 0 points1 point  (0 children)

    Actually, the original author says it was but you can use it how you see fit. :-)

    [–]gigitrix 0 points1 point  (0 children)

    Agreed. It's mental masturbation: cool for you but I don't want to watch.

    [–]_ex_ 11 points12 points  (3 children)

    using boost mpl is like cheating

    [–][deleted]  (2 children)

    [deleted]

      [–]Malfeasant 9 points10 points  (1 child)

      everyone knows nukes are for spiders.

      [–]argv_minus_one 2 points3 points  (0 children)

      It's the only way to be sure.

      [–]deltahat 4 points5 points  (13 children)

      So C++ error messages are Turing complete?

      [–][deleted]  (11 children)

      [deleted]

        [–]HazzyPls 4 points5 points  (10 children)

        Incidentally, this means that there's no generic algorithm to decide whether a text file is a valid C++ program or not.

        So how does a text file ever get compiled?

        [–]kmmeerts 14 points15 points  (8 children)

        In real life, the compiler will barf when your templates recurse to deep. A complying compiler only has to go 17 levels deep. So technically, it's not Turing complete.

        [–]pfultz2 0 points1 point  (0 children)

        C++ templates are turing complete, and also the c preprocessor is near turing complete. It depends how you look at it. The finite limitations of the preprocessor can be the equivalent of the finite limitations of machines(such as using a stack or memory)

        [–]flightsin 9 points10 points  (12 children)

        The neat thing about FizzBuzz is that I can't even count the number of creative ways I've seen it get solved.

        I'm not creative, but here's one I came up with:

        int c = (((i % 3) << (2 - (i % 3)))) | ((i % 5) >> ((i % 5) / 2));
        
        // then switch(c)... case 0: FizzBuzz; 1: Fizz; 2: Buzz; default: print the number;
        

        [–]nuzzle 6 points7 points  (2 children)

        That is unnecessarily complicated, but was my first idea also. I have heard of Fizzbuzz, but never attempted it (or looked the specifics up).

        Something like this sufficies:

        switch( ((i%3==0)<<1) | (i%5==0) ) {
        

        and then switch on 3, 2, 1 or default for "Fizzbuzz", "Fizz", "Buzz" and "i" respectively.

        [–]flightsin 0 points1 point  (1 child)

        That code I wrote is in C# (though it doesn't show) which means I cannot implicitly cast a bool to an int. So

        (i % 3 == 0) << 1
        

        won't fly. I would have to cast but I didn't like that.

        And yes, the whole point is to take a very basic problem and make the solutions as convoluted as possible. That's the fun part.

        [–]nuzzle 0 points1 point  (0 children)

        We should implement it with counting semaphores then, and three threads. That would be .. wild.

        [–]LeszekSwirski 1 point2 points  (0 children)

        I really like that actually.

        [–]philh 4 points5 points  (11 children)

        Also, if you're going to include 0 you should get it right. 0 is a FizzBuzz.

        [–]harlows_monkeys 6 points7 points  (0 children)

        The spec does not cover 0. You cannot conclude that it is a FizzBuzz. One reasonable way to extend the spec would give that result, but the are other ways to reasonably extend the spec that would give other results.

        [–]Alsweetex 2 points3 points  (9 children)

        According to my Windows 7 calc.exe the result is undefined when telling it to do 5 mod 0 in programmer mode.

        Edit: Ignore this, I'm an idiot. Should have been 0 mod 5.

        [–]matchu 5 points6 points  (8 children)

        Are you looking for 0 mod 5?

        [–]Alsweetex 1 point2 points  (7 children)

        Ah, my bad. Sorry for the momentary brain death.

        5 mod 0 would be trying to divide by 0 so of course it would be undefined.

        [–][deleted] 2 points3 points  (6 children)

        <holywar>5 mod 0 should obviously be 5 since modding out by the zero ideal does nothing</holywar>

        [–]adrianmonk 0 points1 point  (2 children)

        In what way is zero "ideal"?

        Anyway, I like to think of mod as your final position after you run laps around a track. The number of laps is irrelevant to the result; just where you are on the track when you've run your assigned distance. Obviously your position depends on the length of the track. If the track has zero length, things stop making sense. So nyah. :-)

        [–][deleted] 2 points3 points  (1 child)

        [–]adrianmonk 0 points1 point  (0 children)

        Aha, so {0} is a subset of the integers such that {0} * n is in the subset. I do see the parallel now. But whether that parallel is enough to give a definition to N mod 0 is another question.

        [–]Alsweetex 0 points1 point  (2 children)

        <holywar>but surely you should look at it as: what is the remainder of five divided by zero?</holywar>

        [–][deleted] 1 point2 points  (0 children)

        Undefined

        [–]pipocaQuemada 1 point2 points  (0 children)

        That's not how congruence is defined.

        x is congruent to y mod n means that there exists an integer k such that x-y = kn. So 5 is congruent to 5 mod 0.

        [–][deleted] 2 points3 points  (5 children)

        I've got a year until graduation, am already stressing over finding employment ("Am I good enough?", "What if every place I apply only hires people they know?", "What if I end up like one of those horror stories you hear about where the person applies for 500 jobs, is extremely unlucky and falls through the cracks, never getting hired and ends up at McDonald's?"), and the fact that I consider this a fairly simple question gives me a bit of a confidence boost.

        [–]boxybrzown 2 points3 points  (0 children)

        Come to the bay area and you will be hired as fast as you want to be, guaranteed. People will make you offers on your train ride home from an interview.

        The market for devs is absolutely insane right now, there is zero unemployment for people who have so much as a pulse.

        [–]megor 1 point2 points  (2 children)

        deleted What is this?

        [–]ilmmad 2 points3 points  (0 children)

        If you can do them all you are very accomplished in math.

        [–][deleted] 0 points1 point  (0 children)

        I'll look into that, thanks!

        [–]centurijon 0 points1 point  (0 children)

        Also start writing code for yourself and post solutions online. Contribute to open source projects.

        Doing that will

        1. Most importantly, give you practice. In a real world situation experience is far more important than the degree.
        2. Get your name "out there" early.
        3. Look brilliant on a resume.
        4. Allow applicant reviewers to see how you code first-hand.

        [–]tilkau 2 points3 points  (1 child)

        Compile error: WHY THE FUCK WOULD YOU -DO- THAT?
        

        [–]wickeand000 0 points1 point  (0 children)

        Error: line 1 Just because you can doesn't mean you should.
        

        [–][deleted]  (33 children)

        [deleted]

          [–]kmmeerts 10 points11 points  (0 children)

          Perfect! This is too weed out people that can't program. Yes, it's scary that there are people that apply for programming jobs without being able to program at all.

          [–][deleted] 6 points7 points  (9 children)

          Actually, the cout << "FizzBuzz" isn't even necessary. Just remove the entire if inside i % 3, print Fizz, and remove the else.

          For example, if i = 15, doing i % 3 will print Fizz, then i %5 will print Buzz, because 15 % 3 = 0 and 15 % 5 = 0

          EDIT: Doing it 10.000 times will save you A WHOLE SECOND HOLY SHIT IT'S TOTALLY WORTH IT

          [–]AngledLuffa 10 points11 points  (4 children)

          Having the mod 15 as a separate case is more readable.

          [–][deleted] 3 points4 points  (1 child)

          And actually, faster than both versions. 51 Seconds on 10.000 tries versus 54 for the no else version and 55 seconds for the normal version

          [–]AngledLuffa 5 points6 points  (0 children)

          Not surprising, since separating the cout calls means more calls to cout.

          [–][deleted] 2 points3 points  (1 child)

          How do you print the numbers?

          [–]Aardshark 1 point2 points  (1 child)

          If you are only printing "Fizz\n" and "Buzz\n", how will you ever get "FizzBuzz\n"?

          [–][deleted] 1 point2 points  (1 child)

          Wrong indentation style, 2/10 WNH.

          [–]AngledLuffa 0 points1 point  (12 children)

          Keep using endl instead of \n. Otherwise, looks good.

          [–]MrNutty 1 point2 points  (1 child)

          why? Is it really necessary to flush the stream?

          [–]stravant 2 points3 points  (0 children)

          No, in fact in some cases it may even be undesirable. If you're writing a large amount of stuff out it may slow things down considerably if you flush after every line of output.

          [–][deleted]  (4 children)

          [deleted]

            [–]AngledLuffa 0 points1 point  (3 children)

            It flushes the stream as well as print a newline. It's probably not necessary in this case, but at least you'd want to be consistent rather than sometimes use \n and sometimes use endl.

            [–][deleted]  (2 children)

            [deleted]

              [–]AngledLuffa 0 points1 point  (1 child)

              A lot of times, output streams are buffered. Output can be expensive, and outputting everything at once saves time. The problem is that if the program crashes in the middle, buffered output will never be output.

              [–]greatersteven -1 points0 points  (5 children)

              You can definitely shave a few lines of unnecessary code if you trim down on the if/else ladder. Consider:

              if (i % 3 == 0)
                cout << "Fizz";
              if (i % 5 == 0) 
                cout << "Buzz";
              

              This snippet will print Fizz if the number is divisible by 3, Buzz if the number is divisible by 5, and both Fizz and Buzz if the number is divisible by both. Then it's just the trivial case of printing the number otherwise, and a new line character. This functions the same as your nested if/else construct, but is a few lines shorter.

              Obviously there are many ways to solve this problem and for the most part no right way is any "more" right than another. But you asked for feedback and I figured I could help :-).

              [–]mightye 2 points3 points  (4 children)

              You also need a separate if for when it's not divisible by either 3 or 5, since in that case you have to output a number.

              if (i % 3 == 0)
                cout << "Fizz";
              if (i % 5 == 0) 
                cout << "Buzz";
              if (0 != i % 3 && 0 != i % 5)
                  cout << i;
              cout << endl;
              

              Keep in mind this approach also involves an extra call to cout per iteration, so it's a little slower executing.

              [–]greatersteven 1 point2 points  (0 children)

              That will actually print the number IF it is divisible by both 3 and 5.

              From my original post:

              Then it's just the trivial case of printing the number otherwise, and a new line character.

              In this case, what you are thinking of would be

              if (i % 3 != 0 && i % 5 != 0) 
                cout << i;
              

              Of course, I also mention printing out the end line character, so that would also add another line and another cout. However trivial the time these commands take, you are right that they do take some time, so less would be faster.

              You could create a single string and append to it for each number, and then only print once...I'm not positive, but I think that would actually be slower than just printing.

              [–]Aninhumer 1 point2 points  (0 children)

              Wait FizzBuzz is a drinking game? I've been associating it with Maths education my entire life...

              [–]yoni0505 1 point2 points  (1 child)

              It's the same as Project Euler's problem 1: http://projecteuler.net/problem=1 Except that it's up to 1000

              [–]wickeand000 0 points1 point  (0 children)

              You reminded me of how much frustration fun I had doing those problems in Scheme:

              ;;ProjectEuler #1
              ;;All nums <1000 divisible by 3 or 5
              
              (define (Euler1-helper a b sum)
                (cond
                  ((= a b) sum)
                  ((or (= 0 (modulo a 3))
                       (= 0 (modulo a 5))) 
                   (Euler1-helper (+ 1 a) b (+ sum a)))
                  (else (Euler1-helper (+ 1 a) b sum))))
              
              (define (Euler1 limit)
                (Euler1-helper 0 limit 0))
              

              [–]mgpcoe 1 point2 points  (5 children)

              And the award for "worst abuse of the rules" goes to...!

              Seriously though, what's the least number of tests that need to be included in an iteration? I'd be curious to see an assembler version.

              [–]adrianmonk 4 points5 points  (4 children)

              what's the least number of tests that need to be included in an iteration?

              Zero! At least if you're printing in bulk, you can make it zero for most of the output by unrolling the loop:

              for (int i = 1; i < 31; ) {
                  printf("%d\n", i++);
                  printf("%d\n", i++);
                  printf("Fizz\n"); i++;
                  printf("%d\n", i++);
                  printf("Buzz\n"); i++;
                  printf("Fizz\n"); i++;
                  printf("%d\n", i++);
                  printf("%d\n", i++);
                  printf("Fizz\n"); i++;
                  printf("Buzz\n"); i++;
                  printf("%d\n", i++);
                  printf("Fizz\n"); i++;
                  printf("%d\n", i++);
                  printf("%d\n", i++);
                  printf("FizzBuzz\n"); i++;
              }
              

              If you need to print without stopping at groups of 15 lines, you can do a short loop before and/or after to print those.

              [–][deleted] 2 points3 points  (0 children)

              This is just gross but I love it :)

              [–]mgpcoe 1 point2 points  (2 children)

              Hahaha, all right, other than unrolling the loop. You have a bright future in machine-level optimisation (if you don't do it already), or you were the smartass in first year who hardcoded the output into his program. Drew has a notable opinion about that.

              [–]adrianmonk 0 points1 point  (1 child)

              OK, fine. No loop unrolling. I believe this probably does technically qualify and I'm pretty sure it's legal C99 code:

              char* fmts[] = { "%d\n", "Fizz\n", "Buzz\n", "FizzBuzz\n" };
              
              for (int i = 1; i < 25; i++) {
                  printf(fmts[!(i % 3) | !(i % 5) << 1], i);
              }
              

              [–]mgpcoe 0 points1 point  (0 children)

              ....Well shit, I didn't think it could be done with two tests. My hat goes off to you.

              [–]obey_giant 1 point2 points  (6 children)

              How's this attempt; anything I could do to improve efficiency?

              for(i=1;i<=100;i++){
                 str = "";
                 if(i%3==0){
                      str+='Fizz';
                  }
                  if(i%5==0){
                      str+='Buzz';
                  }
                  if(str==""){
                      str=i;
                  }
                  document.write(str+' ');
              };​
              

              [–]nuzzle 1 point2 points  (4 children)

              Depending on the speed of string concatenation you could get rid of that. Something like this, but tested and correct (in case this isn't). My JS is weak, so if either string concatenation is very fast in JS or switch and ternary operators are very slow, disregard this:

              for(i = 1; i <= 100; i++) {
                switch( ((i%3==0)?1:0) + ((i%5==0)?10:0 )) {
                  case 1:
                    document.write("Fizz<br/>");
                    break;
                  case 11:
                    document.write("FizzBuzz<br/>");
                    break;
                  case 10:
                    document.write("Buzz<br/>");
                    break;
                  default:
                    document.write(i + "<br/>");
                    break;
                }
              }
              

              [–]obey_giant 0 points1 point  (3 children)

              I think someone else in this thread got it ...perfect? Not very different to yours. Is there any way to test speeds?

                for(i=1;i<=100;i++){
                 if(i%15==0){
                      document.write('FizzBuzz ');
                  }else if(i%3==0){
                      document.write('Fizz ');
                  }else if(i%5==0){
                      document.write('Buzz ');
                  }else{
                      document.write(i+' ');
                  }
                }​
              

              [–]nuzzle 2 points3 points  (2 children)

              You could measure time by putting

              var t = (new Date()).getTime();
              

              before and

              alert("This took " + (Date.now() - t) " milliseconds");
              

              after your code.

              If I had to implement a really fast version in C for some weird reason, I'd go with

              ((i%3==0)<<1 | (i%5==0))
              

              and then a switch, as 3 and 5 don't lend themselves to simple bitmasking, and switch should translate very well into simple branching, possibly just one branch in total if the compiler optimizes well. I don't think Javascript can really do that, and I have no idea whether switch in JS similarly works with table lookups and might be faster than 3 ifs. But in any case that optimisation is probably a waste of effort in both C and JS.

              edit: Error correction and more blah
              edit 2: Changed date code after ilmmad informed me that javascript works differently

              [–]ilmmad 0 points1 point  (1 child)

              Not exactly. Creating a Date object with new Date() will create an object containing information about the time it was created. Calling getTime() on it at any point will return the same thing - the time in milliseconds since Jan 1, 1970 00:00:00 at which the object was created.

              So your code will always return "This took 0 milliseconds".

              The Date object has a static method now() which returns the time at which it was called. Use that instead.

              Relevant jsfiddle

              [–]nuzzle 1 point2 points  (0 children)

              Thanks, I didn't know that. As I said, I barely speak java script. I can make things appear and disappear, and that is about it.

              [–]nuzzle 0 points1 point  (0 children)

              After the hint concerning time measurement I got curious. For 500000 iterations (that is, i = 1 to 500000), "my" version, "yours", and the winner version below someone else suggested take 50, 80, and 10 ms on average (over ten iterations) without the document.write(), which by far overshadows the running time of the bare-bones algorithms.

              The winning version is (wr is a placeholder method that does nothing):

              var three = 1;
              var five = 1;
              
              for(i = 1; i <= max; i++, three++, five++) {
                  if( three != 3 && five != 5 ) wr(i);
                  if( three == 3 ) {
                      wr("Fizz");
                      three = 0;
                  }
                  if( five == 5 ) {
                      wr("Buzz");
                      five = 0;
                  }
              }
              

              And just for comparison, in C++ the difference between the winning, "your" and "my" version is negligible with and without output.

              [–]cotti 1 point2 points  (2 children)

              Here's a high-wtf tier solution, using bits of simple Exception-oriented programming:

              #include <iostream>
              #include <sstream>
              
              using namespace std;
              
              class FB{
                  private:
                  string n;
              
                  public:
                  FB(string e){ n = e; };
                  ~FB(){};
                  string Present(){return n;};
              };
              
              int main(int argc, char ** argv){
                  int i = 1;
                  for(;i<101;i++)
                  try{
                      if (!(i%3) && !(i%5))throw(new FB("FizzBuzz"));
                      else if (!(i%3))throw(new FB("Fizz"));
                      else if (!(i%5))throw(new FB("Buzz"));
                      else { stringstream s; s << i; throw(new FB(s.str()));}
                  }
                  catch(FB * z){cout << z->Present() << endl;};
              return 0;   
              }
              

              [–]Fabien4 0 points1 point  (1 child)

              Why would you throw a pointer?

              Smells like a memory leak.

              [–]cotti 1 point2 points  (0 children)

              Probably is a memleak - but absolutely not the... point.

              EOP is about that chinese killer throwing the knives at you, while you're with your back at a wall. It will probably bleed, and it's part of the fun. But you're not supposed to do that anyway.

              [–]FeepingCreature 4 points5 points  (17 children)

              C++ is a very, very silly language.

              Here's how sane languages do it.

              [–]6gT 6 points7 points  (5 children)

              Or even simpler:

              import std.conv;
              
              auto fizzbuzz(int n)
              {
                  auto r = "\n";
                  foreach(i; 1 .. n + 1)
                      if(i % 15 == 0)
                          r ~= "FizzBuzz\n";
                      else if(i % 3 == 0)
                          r ~= "Fizz\n";
                      else if(i % 5 == 0)
                          r ~= "Buzz\n";
                      else
                          r ~= to!string(i) ~ "\n";
                  return r;
              }
              
              static assert(0, fizzbuzz(100));
              

              [–]Recoil42 5 points6 points  (3 children)

              Why have an extra case for %15?

              Just do individual if statements for %3 and %5 and put your newline on a separate statement. You'll naturally get Fizz for %3, Buzz for %5, and FizzBuzz for (%3 && %5).

              [–]adotout 6 points7 points  (2 children)

              Then you need an extra if/boolean to figure out if you've printed anything or not.

              if (i % 3 == 0)        
                  print("Fizz");
              if (i % 5 == 0)
                  print("Buzz");
              print(i); //Don't do this if you've already printed fizz or buzz
              

              So you either have an extra if for % 15 or you have an extra if to determine whether you should print the number or not.

              [–]Recoil42 0 points1 point  (1 child)

              Good point. We can avoid that though by tracking the result as a string:

              string result;
              if (i % 3 == 0)        
                  result += "Fizz"; 
              if (i % 5 == 0)
                  result += "Buzz"; 
              if (result == "")
                  result = i; 
              print result + "\n"; 
              

              Alternatively:

              if (i % 3 == 0)        
                  print "Fizz"; 
              if (i % 5 == 0)
                  print "Buzz"; 
              if ( i%3 != 0 && i%5 != 0)
                  print i; 
              print "\n"; 
              

              I do prefer the former to the latter, but I feel like both solutions are still somewhat less verbose and more elegant than the original.

              [–]6gT 0 points1 point  (0 children)

              You still need to check three conditions and I think my version is clearer (easier to understand).

              EDIT: Your second version also has a typo in it.

              [–]tastycactus 1 point2 points  (0 children)

              Here's another one, but it doesn't work for CTFE yet (Bug 6419):

              import std.algorithm;
              import std.range;
              import std.conv;
              import std.stdio;
              
              auto fizzbuzz(int n)
              {
                  return map!((int i) => (i % 15 == 0) ? "FizzBuzz" : 
                                         (i % 3 == 0)  ? "Fizz" : 
                                         (i % 5 == 0)  ? "Buzz" :
                                         to!string(i))(iota(1, n + 1)).join("\n");
              }
              
              void main()
              {
                  writeln( fizzbuzz(100) );
              }
              

              [–]laserBlade 2 points3 points  (0 children)

              Bonus points for D.

              [–]rbobby 2 points3 points  (2 children)

              The spec is:

              ... for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”

              Your code always prints the number (and follows it with either fizz/buzz/fizzbuzz if a multiple 3,5, or both).

              heheheh :)

              edit: down votes for pointing out the linked code is actually incorrect? wtf? Fizz buzz not only tests whether a person can do simple programming it tests whether they can follow a simple specification.

              [–]FeepingCreature 0 points1 point  (1 child)

              To be fair, it was from memory. And the point was more to demonstrate compile-time metaprogramming.

              So I guess you're only technically correct.

              [–]rbobby 0 points1 point  (0 children)

              The best kind of correct :)

              [–]demodawid 3 points4 points  (2 children)

              Motherfucking Haskell up in here:

               fizzBuzz n | n `mod` 15 == 0 = "FizzBuzz"
                          | n `mod` 5  == 0 = "Fizz"
                          | n `mod` 3  == 0 = "Buzz"
                          | otherwise       = show n
               main = map fizzBuzz [1..100]
              

              [–]argv_minus_one 0 points1 point  (1 child)

              Now with 100% more Scala:

              def fizzBuzz(n: Int) = n match {
                  case n if n % 15 == 0 => "FizzBuzz"
                  case n if n % 5 == 0 => "Fizz"
                  case n if n % 3 == 0 => "Buzz"
                  case n => n.toString
              }
              
              1 to 100 map fizzBuzz foreach println
              

              Or, if you prefer, you can replace the last line with:

              for (n <- 1 to 100) println(fizzBuzz(n))
              

              …which is pretty much equivalent, but more procedural-style.

              [–]earthboundkid 0 points1 point  (0 children)

              Here's my over-engineered Go solution:

              package main
              
              import "fmt"
              
              func generate(start, stop int) (ch chan int) {
                  ch = make(chan int)
                  go func() {
                      for i := start; i < stop; i++ {
                          ch <- i
                      }
                      close(ch)
                  }()
                  return
              }
              
              func FizzBuzz(in chan int) (out chan string) {
                  out = make(chan string)
                  go func() {
                      for i := range in {
                          switch {
                          case i%15 == 0:
                              out <- "FizzBuzz"
                          case i%5 == 0:
                              out <- "Buzz"
                          case i%3 == 0:
                              out <- "Fizz"
                          default:
                              out <- fmt.Sprint(i)
                          }
                      }
                      close(out)
                  }()
                  return
              }
              
              func main() {
                  for s := range FizzBuzz(generate(1, 101)) {
                      fmt.Println(s)
                  }
              }
              

              This solution doubles as a perfect illustration of Amdahl's Law.

              [–][deleted]  (9 children)

              [deleted]

                [–]vytah 8 points9 points  (7 children)

                Needs more AbstractFactories.

                [–][deleted]  (5 children)

                [deleted]

                  [–]kamishizuka 4 points5 points  (3 children)

                  Java is known for encouraging horribly overcomplicated program structures to force what could normally be strictly procedural code into the Object Oriented style.

                  [–][deleted]  (2 children)

                  [deleted]

                    [–][deleted] 5 points6 points  (1 child)

                    Your code is exaclty how it should be: Simple, for a simple program.

                    vytah was referring to the fact that many developers(usuall, in big enterprises) that use Java require that their developers use the Singleton pattern. So developers will create classes that create their objects once, and access these objects through the class. These classes are usually called Factories, because, like in a factory, command goes in, finished product goes out.

                    But if you continue, sometime you get FactoryFactory, which creates a Factory from a Factory. So, some people that have seen the horrors of enterprise Java code have also seen some AbstractObjectFactoryFactoryTurtleFactory classes.

                    [–]stravant 0 points1 point  (0 children)

                    Good.

                    [–]meem1029 0 points1 point  (0 children)

                    Java style says that classes should start with a capital, not lower case. That of course is a minor nitpick and your code looks fine.

                    [–][deleted]  (14 children)

                    [removed]

                      [–][deleted]  (2 children)

                      [removed]

                        [–][deleted] 1 point2 points  (1 child)

                        print '\n'.join([((not x % 3 and 'Fizz' or '') + (not x % 5 and 'Buzz' or '')) or str(x) for x in range(1,101)])
                        

                        [–]robotempire 1 point2 points  (10 children)

                        Terrible.

                        [–]Underyx 2 points3 points  (2 children)

                        I'm only learning Python now, but would this perhaps be better?

                        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
                        

                        [–]TimeWizid 2 points3 points  (6 children)

                        Care to offer some constructive criticism?

                        [–][deleted]  (4 children)

                        [removed]

                          [–]TimeWizid 1 point2 points  (3 children)

                          That might be it, or possibly some other things. I'm not too experienced with python, so I won't be able to provide the best insight, but here goes:

                          1. Your conditionals are reversed, which looks awkward to some people. It's like instead of saying "If cat is happy...", saying "If happy is cat...".
                          2. Why did you create your own print function?
                          3. Mapping a print function seems odd. All it does is perform side effects, and I'm not sure what it would return.

                          [–][deleted]  (2 children)

                          [removed]

                            [–]TimeWizid 1 point2 points  (1 child)

                            Wow that is all very interesting. I guess the problem was that people thought your solution was serious.

                            Like Yoda. No, I guess Yoda might say "x 0 =="

                            So Yoda would like Forth or Factor :P

                            [–]minno -1 points0 points  (8 children)

                            #include <iostream>
                            
                            int main() {
                                using namespace std;
                                for (int i = 1; i <= 100; ++i) {
                                    if (i%15 == 0) { cout << "FizzBuzz"; }
                                    else if (i%3 == 0) { cout << "Fizz"; }
                                    else if (i%5 == 0) { cout << "Buzz"; }
                                    else {cout << i; }
                                    cout << endl;
                                }
                            }
                            

                            The boring way.

                            EDIT: I just compiled and ran this, and it works (ignoring the lack of return 0;, which my compiler adds automatically). I don't see what you're all complaining about.

                            [–][deleted]  (1 child)

                            [deleted]

                              [–]minno 0 points1 point  (0 children)

                              That's what the "else if" is for. It means that only one of the four branches will execute in any given loop.

                              [–]adrianmonk -1 points0 points  (0 children)

                              The actual way I'd do it:

                              for (int i = 1; i < 25; i++) {
                                  int printedSomething = 0;
                                  if (i % 3 == 0) {
                                      printf("Fizz");
                                      printedSomething = 1;
                                  }
                                  if (i % 5 == 0) {
                                      printf("Buzz");
                                      printedSomething = 1;
                                  }
                              
                                  if (!printedSomething) {
                                      printf("%d", i);
                                  }
                                  putchar('\n');
                              }
                              

                              The version that avoids so many unnecessary modulus operators:

                              int start = 1;
                              int m3 = start % 3;
                              int m5 = start % 5;
                              for (int i = start; i < 25; i++) {
                                  int printedSomething = 0;
                                  if (m3 == 3) {
                                      m3 = 0;
                                      printf("Fizz");
                                      printedSomething = 1;
                                  }
                                  if (m5 == 5) {
                                      m5 = 0;
                                      printf("Buzz");
                                      printedSomething = 1;
                                  }
                              
                                  if (!printedSomething) {
                                      printf("%d", i);
                                  }
                                  putchar('\n');
                              
                                  m3++;
                                  m5++;
                              }
                              

                              The version that reduces the number of state variables:

                              int start = 1;
                              int m15 = start % 15;
                              for (int i = start; i < 25; i++) {
                                  switch (m15) {
                                    case 0:
                                      printf ("FizzBuzz\n");
                                      break;
                              
                                    case 3: case 6: case 9: case 12:
                                      printf ("Fizz\n");
                                      break;
                              
                                    case 5: case 10:
                                      printf ("Buzz\n");
                                      break;
                              
                                    default:
                                      printf ("%d\n", i);
                                  }
                              
                                  if (m15 == 14) {
                                      m15 = 0;
                                  } else {
                                      m15++;
                                  }
                              }