1. ## 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++

Output

I did this because I was bored

2. ## Re: FizzBuzz

C#

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. ## Re: FizzBuzz

Pretty lame code (C++)

Bonus points? Random generator

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

???

4. ## Re: FizzBuzz

Yayyyy Python!

Code:
```
for i in range(1, 101):
if (i % 3 == 0) and (i % 5 == 0):
print("FizzBuzz")
elif (i % 3 == 0):
print("Fizz")
elif (i % 5 == 0):
print("Buzz")
else:
print(i)```
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. ## Re: FizzBuzz

Those are unnecessary.

6. ## Re: FizzBuzz

classic C - write-only style

7. ## Re: FizzBuzz

The continues? Yes they are.

Output without continues

8. ## Re: FizzBuzz

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

9. ## 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".

Spoiler

11. ## 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.

Spoiler

12. ## Re: FizzBuzz

Not all languages support Unicode like that.

13. ## Re: FizzBuzz

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

PHP Code:
``` using System;using System.Linq;namespace NIC2{    internal class Program    {        private static void Main(string[] args)        {            foreach (int x in Enumerable.Range(1, 100))                if (x%15 == 0) Console.WriteLine("FizzBuzz");                else if (x%3 == 0) Console.WriteLine("Fizz");                else if (x%5 == 0) Console.WriteLine("Buzz");                else Console.WriteLine(x);        }    }}  ```

#### Posting Permissions

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