Results 1 to 13 of 13

Thread: FizzBuzz

  1. Default FizzBuzz

    I'm sure all of you guys know what the FizzBuzz programming question is. It's typically used for weeding out people who can't code in interviews, though I don't really know how prominent it is now a days. There was an interesting blog post by Jeff Atwood a couple years ago about FizzBuzz and how people couldn't do it that was rather interesting.

    So in this thread, implement FizzBuzz in your programming language of choice with a twist on it or just regular FizzBuzz.

    For those interested in what FizzBuzz is.
    Loop through 100 numbers.
    If the number is divisible by 3, print Fizz.
    If the number is divisible by 5, print Buzz.
    If the number is divisble by both, print FizzBuzz
    If the number isn't divisible by either, print the number.

    Should be an interesting way to see coding styles here in Southperry.

    Use the [code] or [php] tag to format your code

    TMP C++


    I did this because I was bored

  2. Default Re: FizzBuzz


    There wouldn't be any significant difference between two implementations in the same language so it doesn't demonstrate "coding style".

    At the job interview for where I currently work, I didn't have to do fizzbuzz but I did have to do a couple problems. One was simply to write a function to reverse a string. The other was only a bit harder than string reverse with a naive algorithm and considerably more difficult if you're going for a more efficient solution. It was done on a website that automatically runs and tests your solution. This was after the phone interview but before the in-person interview. The solution I submitted for the second problem was the naive algorithm. The website ran it on input of increasing size to see if it terminates with the correct answer in a certain timeframe. Being the naive algorithm, it wasn't able to handle the largest input. The interviewer told me to see if I could improve it, so I spent several hours working on a more efficient algorithm and came to the in-person interview with printouts of the code along with unit tests and benchmarks comparing it to the naive algorithm. I think the interviewers were impressed.

    I don't do any of the interviewing of candidates, but from what I understand, there are plenty of people who apply for a programming job who couldn't program their way out of a paper bag.

    Now for a more interesting question: give an example of a string where printing the result of the standard string reverse algorithm does not give what you might consider the reverse of the string.

  3. Default Re: FizzBuzz

    Pretty lame code (C++)

    Bonus points? Random generator

    Derp. I don't know. Even forgot a continue.


  4. Default Re: FizzBuzz

    Yayyyy Python!

    for i in range(1, 101):
        if (i % 3 == 0) and (i % 5 == 0):
        elif (i % 3 == 0):
        elif (i % 5 == 0):
    Do people seriously apply for programming jobs when they can't program?!

    I was worried about my programming ability when I get a job, but I can definitely write programs that are this simple with no effort o_o

    As for the strings question... I'm guessing it involves a special character?

  5. Default Re: FizzBuzz

    Those are unnecessary.

  6. Orbital Bee Cannon
    IGN: SaptaZapta
    Server: Kradia
    Level: 214
    Job: Hero
    Guild: Matriarchy
    Alliance: Dominion

    Default Re: FizzBuzz

    classic C - write-only style

  7. Default Re: FizzBuzz

    The continues? Yes they are.

    Output without continues

  8. aka ClawofBeta Straight Male
    Corn's Avatar [Jr. Event Coordinator]

    IGN: ClawofBeta
    Server: LoL.NA
    Level: 30
    Job: Bot Lane
    Guild: N/A
    Alliance: N/A

    Default Re: FizzBuzz

    I would totally do the same way as Heidi's, but in the range (0, 100) instead =P.

  9. Orbital Bee Cannon
    IGN: SaptaZapta
    Server: Kradia
    Level: 214
    Job: Hero
    Guild: Matriarchy
    Alliance: Dominion

    Default Re: FizzBuzz

    They are only necessary because you didn't use "else if".

    Generally speaking, "continue" and "break" should only be used when it would require convoluted logic to avoid them, as they are a form of the dread "goto".

  10. Default Re: FizzBuzz


  11. Default Re: FizzBuzz

    If you're using a language where strings are null-terminated, then you cannot by definition have a \0 "inside" the string. The string "hel\0lo" is equivalent to the string "hel" when you're using null-terminated strings.

    Having a newline inside the string, it still gets reversed as you would expect.

    If you're working with null-terminated strings and your string reverse algorithm puts the null terminator at the beginning, your algorithm is wrong.

    I guess no one's getting it. Here's what I was going for.


  12. Default Re: FizzBuzz

    The OP's code loops through 101 numbers, not 100.

    PHP Code:
    using System;
    using System.Linq;

    internal class Program
            private static 
    void Main(string[] args)
                foreach (
    int x in Enumerable.Range(1100))
                    if (
    x%15 == 0Console.WriteLine("FizzBuzz");
                    else if (
    x%== 0Console.WriteLine("Fizz");
                    else if (
    x%== 0Console.WriteLine("Buzz");



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts