jump to navigation

Using FizzBuzz to Find Developers who Grok Coding January 24, 2007

Posted by tickletux in Software development, job interviews.
trackback

On occasion you meet a developer who seems like a solid programmer. They know their theory, they know their language. They can have a reasonable conversation about programming. But once it comes down to actually producing code they just don’t seem to be able to do it well.

You would probably think they’re a good developer if you’ld never seen them code. This is why you have to ask people to write code for you if you really want to see how good they are. It doesn’t matter if their CV looks great or they talk a great talk. If they can’t write code well you probably don’t want them on your team.

After a fair bit of trial and error I’ve come to discover that people who struggle to code don’t just struggle on big problems, or even smallish problems (i.e. write a implementation of a linked list). They struggle with tiny problems.

So I set out to develop questions that can identify this kind of developer and came up with a class of questions I call “FizzBuzz Questions” named after a game children often play (or are made to play) in schools in the UK.

In this game a group of children sit around in a group and say each number in sequence, except if the number is a multiple of three (in which case they say “Fizz”) or five (when they say “Buzz”). If a number is a multiple of both three and five they have to say “Fizz-Buzz”.

An example of a Fizz-Buzz question is the following:

Write a program that prints the numbers from 1 to 100. 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”.

Most good programmers should be able to write out on paper a program which does this in a under a couple of minutes.

Want to know something scary ? – the majority of comp sci graduates can’t. I’ve also seen self-proclaimed senior programmers take more than 10-15 minutes to write a solution.

I’m not saying these people can’t write good code, but to do so they’ll take a lot longer to ship it. And in a business environment that’s exactly what you don’t want.

This sort of question won’t identify great programmers, but it will identify the weak ones. And that’s definitely a step in the right direction.

Comments»

1. Monkeyget - January 24, 2007

I have asked a fizzbuzz question recently. The position was for a .NET developer.
I asked a candidate who claimed to have “one year of experience in .NET” to create the simplest thing I could think of: an application that takes two number and displays the sum of them.
It took five minuts and a bit of my help just to create a new project, as much time to create the visual aspect of the window (drag and drop 2 textbox and a button!) and in the end it didn’t even compiled.

Actually I don’t think asking a “Fizz-Buzz” question is a good thing and I wouldn’t recommend on doing it. I only did it because I knew the candidate wasn’t worth it and wanted to demonstrate it to the boss which had no technical knowledge and therefore couldn’t understand that not knowing what an interface is and not being able to describe what a class and an object are, is a big no-no.
As you said, you still don’t know if he can write good code. You only know that he/she can write the most basic code but you lost some precious time for the interview. Is it worth it? Maybe asking to design and write something more complicate but not that complicate would be better.

Every company worth a damn and caring about who they are hiring : http://weblog.raganwald.com/2006/07/hiring-juggler_02.html

2. Lionel Barret - January 24, 2007

Indeed, such an abysmal level of coding skill is simply unbelievable…
I am speechless…

Frankly, i have never seen candidate so unskilled, but in France, comp.sci is really math heavy and I suppose that’s a good filter.

But still…

3. Jacob - January 24, 2007

Want another good filter? This surprised me, but turns out to be a good indication of whether someone has actually ever programmed before.

Ask: show me (on paper, but better on a whiteboard) how you would swap the values of two variables.

If they don’t *start* with creating a third variable, you can pretty much write that person off. I’ve found that I can cut a third to half my (admittedly at that point unscreened) applicants with that question alone.

Derek Clarke - July 5, 2009

There’s an algorithm to do that without a third variable.

int a = 5;
int b = 13;
a = a+b;
b = a-b; //b now has original value of a
a = a-b; //a now has original value of b

4. Mitch Silverman - January 24, 2007

I once worked at a company that did a lot of geometric computations. Our standard interview question (to be done as homework between interview 1 and interview 2) was write a function in c that would “Chord” a circle to an arbitrary level of precision. Inputs were radius and tolerance. Output was the number of sections needed to break up the circle.
In the second interview we would review the code and talk about error catching, what happens when radius is less than distol.. etc.
But the trick was when we asked for a function to do the same thing with an ellipse. We didnt want an answer – we were looking for the response
Was the candidate excited? Thoughtful? or did (s)he get that deer in the taillights look in his/her eyes?

5. Ben Prew - January 24, 2007

Jacob,

There are several languages that you can do this in that don’t require a temporary variable. I know Perl supports this, and I believe Ruby does as well:

ex.

($a, $b) = ($b, $a)

I’m not sure about Python or other dynamic languages, but I believe they do.

Finally, you can do it in C as well:

void XORSwap(void *x, void *y)
{
*x ^= *y;
*y ^= *x;
*x ^= *y;
}

I’m assuming that you’re eliminating candidates who actually can’t get swap() correct. But, in several cases, not starting by creating a temporary variable is actually a good thing :)

6. Alexandre Vassalotti - January 25, 2007

“Want to know something scary ? – the majority of comp sci graduates can’t.”

That is indeed scary. I have a hard time to believe it. Maybe, the candidates were thinking it was a trick question or something like that. I don’t know.

I took me less than 1 min (I timed myself), to write the correct solution and never taken any course. Now, I’m wandering what they teach in Computer Science courses.

# Fizz-Buzz in Python
for i in range(1, 100):
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

# Swap in Python
a = 0
b = 1
b, a = a, b

Personally, I would ask them, as a weeder question, to write a function that sums up integers from a text file, one int per line.

7. Vineet Kumar - January 25, 2007

I was also going to respond to Jacob’s swap question with the python unpacking example, but Ben and Alexandre beat me to it. Though Ben, in your C example, you can’t dereference a void pointer. I wouldn’t say that really falls in the FizzBuzz category, but it would be a minus point for the interviewee.

8. Jos'h - January 25, 2007

“”"
fizzbuzz.py
josh 2007-01-25
Print integers 1 to 100. Sub ‘Fizz’ for multiples of 3, ‘Buzz’ for mult of 5.
Sub ‘FizzBuzz’ for mults of both. Written for the purpose of being silly.
“”"

threes = range(0, 101, 3)
fives = range(0, 101, 5)

def check(n):
. plain = 1
. if n in threes: print “Fizz”, ; plain = 0
. if n in fives: print “Buzz”,; plain = 0
. if plain: print n,
. print

[check(i) for i in range(1, 101)]

9. Geordan’s Musings » Fizz Buzz - January 25, 2007

[...] came across this post on programming.reddit.com regarding using a very simple exercise to weed out completely inept [...]

10. Mohammed Zainal - January 25, 2007

good post,
i know little programming , learnt by trial & error , internet and books.
i do complicate things while writing my code , prolly because im not really good with math , but yet & the end i’ll find the solution .

candidates some time gets tension during the interview and that will effect the results .

p.s nice blog buddy :)

11. mult.ifario.us : Laziness and fizzbuzz in Haskell - January 25, 2007

[...] peeking at Reg’s solution, I can’t resist posting a fizzbuzz implementation in Haskell (because it looks stylistically like it should be written in an FP [...]

12. flickrhoneys - January 25, 2007

I used to grok coding, but I’ve grown up since then :D

13. Miauw - January 25, 2007

“Ask: show me (on paper, but better on a whiteboard) how you would swap the values of two variables.” (Jacob)

How do you do that in functional languages with single assignment? :)

14. Stephen. - January 25, 2007

Ech, state variables stink. Here’s a better python solution

for i in range(1,100):
fizz = (i % 3 == 0) and “Fizz” or “”
buzz = (i % 5 == 0) and “Buzz” or “”
print “%2i %s%s” % (i,fizz,buzz)

15. john cromartie - January 25, 2007

Fizzbuzz in a nasty Ruby one-liner:

puts (1..100).to_a.collect { |i| i % 15 == 0 ? ‘fizzbuzz’ : (i % 5 == 0 ? ‘fizz’ : (i % 3 == 0 ? ‘buzz’ : i)) }.join(’ ‘)

16. john cromartie - January 25, 2007

“How do you do that in functional languages with single assignment? ” (Miauw)

You wouldn’t have variables to begin with… unless it was a monad, in which case you would just do it the normal way.

17. Joshua - January 25, 2007

Java:
public static void main(String[] args)
{
for (int i = 1; i

18. Jacob - January 25, 2007

Ben,

I’d take anything that works. If I were interviewing for a C or Perl position, your examples would be fine. The key is to pose the question and observe them tackling it. *How* they tackle it is as important as whether they come up with the “right” answer. My example of swapping the values in two variables is a pretty trivial question, so how long it takes and their approach to doing it is the information I’m parsing, not whether they end up in the right place in the end.

19. sibecker - January 25, 2007

Here it is in functional programming (OCaml):
“How do you do that in functional languages with single assignment? ” (Miauw)

OCaml one liner:

let fb x = (if x mod 3 = 0 then “Fizz” else “”) ^ (if x mod 5 = 0 then “Buzz” else “”) in let fb2 x = let f = fb x in if f = “” then string_of_int x else f in let rec fb_to x = let g = fb2 x in if x = 1 then g else (fb_to (x-1)) ^ “, ” ^ g in fb_to 100;;

20. WC - January 25, 2007

def fizzbuzz():
for n in range(1, 101):
str = “”
if not n % 3:
str += “Fizz”
if not n % 5:
str += “Buzz”
print n, str

21. anon for this one - January 25, 2007

Ruby FizzBuzz in 81 bytes. (please let my next employer ask this in an interview… please)

f,b=’fizz’,'buzz’
puts((1..100).to_a.map{|i|i%15==0?f+b:(i%5==0?b:(i%3==0?f:i))})

22. Cale Gibbard - January 25, 2007

Er, what do you mean “the majority of comp sci graduates can’t”? Do you have any data to support that?

At least where I went to uni, not just comp sci graduates, but everyone in first year mathematics had to learn to solve harder programming problems than that. By the end of second year, everyone in comp sci, and a large portion of those in any program in the mathematics faculty will have written a simple compiler. So I don’t see how this problem would be of any difficulty.

I can’t say anything about how typical my university was (in fact, I suspect it’s quite atypical, and I was there for a pure mathematics degree anyway). So sure, this is just one datapoint, but I’m curious about where your conclusions are coming from.

23. goblinfactory - January 25, 2007

How about overloading the assignment operator in C#?

24. Dr Jekyll & Mr Hyde » Blog Archive » FizzBuzz and bored programmers - January 25, 2007

[...] his blog, tickletux advocates the use of FizzBuzz to find developers who grok coding. However, this kind of test may also cause difficulties. What do you do if a candidate answers with [...]

25. azman - January 26, 2007

you’re right about comp sc student didnt rite!
even my friend with master degree in comp science cant even rite “hello world” program!!..hahahah..
nice blog

26. Andrew - January 26, 2007

;; scheme example… though, i’m not happy

(define (fizz-buzz rng)
(let loop ((n 1))
(let ((thr (remainder n 3))
(fiv (remainder n 5)))
(cond
((and (zero? thr) (zero? fiv)) (printf “fizz-buzz~n”))
((zero? thr) (printf “fizz~n”))
((zero? fiv) (printf “buzz~n”))
(else (printf “~a~n” n)))
(if (= rng n)
n
(loop (add1 n))))))

(fizz-buzz 100)

27. Brian Mitchell - January 26, 2007

If you’re going to golf it you might as well check if things like the repetition of values actually helps. Here is something short in ruby.

puts (1..100).map{|i|i%15==0?’FizzBuzz’:i%5==0?’Buzz’:i%3==0?’Fizz’:i}

I’ll also punish anyone on my team who writes a set of nested ternary expressions like that. It’s nice to know those things for golfing games though. ;-)

28. macnod - January 26, 2007

Common Lisp:
(loop for a from 1 to 100 collect
(let ((c (zerop (mod a 3))) (d (zerop (mod a 5))))
(cond ((and c d) “FizzBuzz”)(c “Fizz”)(d “Buzz”)(t a))))

29. Randy - January 26, 2007

Why do people always insist on writing one-liners?

Yes, you may get your rocks off by writing something a litty crazy, but the guy who has to maintain your code, is going to be hating you. Just say no to one-liners. And say yes, to clear, consistent coding.

30. Brian Mitchell - January 26, 2007

Randy, I agree but in this case it looks like it was so easy to solve that people went a little farther and started a game of golf [0].

[0] The original golfing language was perl but it has now become popular way for bored programmers to play with their skills in many different languages.

31. khudari - January 26, 2007

Dave Kaemmer came up with a similar test at Papyrus that I have been using for years.

This kind of test is too simple to measure programming skill, but it is a great predictor of who will be very productive and who will not. We found it much better than a person’s resume, for example. So my technique is to administer the test via email (with a 20 minute time limit) to every applicant after a very basic resume screen. This saves a lot of valuable engineering staff time doing interviews. Our only problem: it is really hard to find candidates we want to interview.

32. George - January 26, 2007

WTF is this on the Daly WTF

33. Jeff Staddon - January 26, 2007

Maybe it’s just economics? With all the technology buzz and high salaries there’s a lot of motivation to jump on board. Especially for a young person who doesn’t really know their strengths/weaknesses. Univ I’m afraid are more interested in selling students on taking classes than on helping these kids find themselves.

All the good developers I’ve known never really choose technology—they were drawn to it as if it were some alien tractor beam. Back in my university years I tried to escape myself–I majored in history–but I couldn’t help but write Perl scripts on the side because it was so much fun! (BTW–anyone else out there majored in history??)

34. Brendan - January 26, 2007

Apologies to Mr. Anon with his 81 bytes, but I did it in ruby in 71.

puts (1..100).map{|i|(s=(i%3==0?’Fizz’:”)+(i%5==0?’Buzz’:”))==”?i:s}

35. Eric - January 26, 2007

Re: No One Liners

I personally enjoy a challenge as a developer and one liners often provide just that. While it is probably not as helpful to folks maintaining code because it can be confusing, I would rather hire someone who will figure it out and learn something then someone who simply brushes things off as being unclear.

I am not saying folks should write everything on one line, be reducing line counts is a good way to learn details of the language along with different ways of implementing algorithms.

36. Brendan - January 26, 2007

I would certainly not put anything like the above in production code.

However, someone who golfs successfully is someone who also knows the syntax precisely – they know when they can go without parentheses, spaces and the like.

Of course, if someone wrote something like the above in a live interview as a first pass, I don’t know whether I’d be more or less inclined to hire them. After all, I sure don’t think well like that.

37. Reg Braithwaite - January 26, 2007

I think it’s important to avoid overthinking the question and the answer. All you want to do is eliminate the extreme time wasters taht have no clue whatsoever.

The key is that someone solves it in fifteen minutes or less. If they want to Golf with it, or show off the fact that they just read a book about Higher Order Functions, I say don’t mark them down but don’t mark them up either.

Just invite them in for the interview. That’s the place where you can find out f they’re too clever by half, or perhaps they were bored, or are really straightforward but thought they needed to show you something special just to get the job.

http://weblog.raganwald.com/2007/01/dont-overthink-fizzbuzz.html

38. Alex - January 27, 2007

Sorry, Ben Prew, but your C solution shouldn’t even compile – I’m afraid you missed the cut for working for tickletux! :)

> void XORSwap(void *x, void *y)
> … dereferencing “void *” …

39. lev radin - January 27, 2007

It seems to me weird that in blog based on PHP nobody offered way how to swap variable in PHP. Here you go:
list($a,$b) = array($b,$a);

40. Philip Munce - January 27, 2007

Not a bad test. Although I sometimes wonder if a dev team needs a couple of guys who can’t code. Reason being is that unless you work for a startup most dev work is repeatative and simple like HTML wording changes. Just the thing for someone who doesn’t know how to go to google and type “how to use modulus arithmetic in “.

41. hairmare - January 27, 2007

crappy code, but written in the time constraints. i actually get the shivers when i see courses like programming HTML on comp sci curriculas. there are also some unis where the industry links are getting to strong and thus hindering real innovation on the merits of making money and protecting IP in new inventions.

42. hairmare - January 27, 2007

$i=1; while ($i

43. Steve Biko - January 27, 2007

Jacob said: “Ask: show me (on paper, but better on a whiteboard) how you would swap the values of two variables.

If they don’t *start* with creating a third variable, you can pretty much write that person off.”

B.S. You can swap the values without a third variable using XOR:

var1 = var1 XOR var2
var2 = var2 XOR var1
var1 = var1 XOR var2

44. Reg Braithwaite - January 28, 2007

Swapping two variables:

The ‘XOR’ thingie is an old C/C++ ‘Aha!’ I’ve never met anyone who figured it out from base principles, everyone seems to have been shown it by someone else.

Nevertheless, it often comes up in C++ interviews and that may not be a bad thing: if you’re a C++ programmer and you’ve never heard of this trick, you probably don’t spend a lot of time actually hanging around other C++ programmers and trading tips (I’m talking to you Mr. “Visual C++ in 21 Days”).

All that being said, the given trick obviously only works in languages where XOR applies to the values given. This will not work with arbitrary Java objects, for example. Although the references might be CPU words, the language won’t let you XOR them or even cast the references to a primitive long.

45. Joshua Volz - January 28, 2007

IMO, it’s not the answer that matters, but the explanation of the answer that they give. If they write something like:

for i in range(1,101):
s = ”
if i % 3 == 0: s = “Fizz”
if i % 5 == 0: s += “Buzz”
if i % 3 != 0 and i % 5 != 0: print i
else: print s

But then told me, “yes, I know I am retesting i in the third clause, but I think it might make the code more understandable,” I would be okay with their answer, especially if they went on to do it in a single liner. I would also accept something like:

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

This at least shows that they realize that if something is divisible by 3 and 5, then it is also divisible by 15 (not a mind-bending fact, but at least they are changing the problem to be expressed without using “not”).

The follow-up question from the interviewer is what is important. If they give either of the previous two solutions (or something similar), and then you ask them to optimize for length of code, or execution time (aka “don’t retest”) and they understand what you want, then you are learning something about them. That’s the real goal of the interview.

The deeper question is what does it say about CS education that this is a reasonable test to give someone to find out if they know what they are doing. Anyone who can’t answer this, even under the stress of an interview, isn’t really a programmer. How could you trust someone with hundreds of thousands of lines of code, and the design of classes (usually) when they can’t do this?

Another fun solution, although convoluted:

for x in range(1,101):
a,b=x%3==0,x%5==0
print “%s%s%s”%(a and “Fizz” or ”, \
b and “Buzz” or ”, not a and not b and x or ”)

## I put the ‘\’ in there so that it wouldn’t wrap in the space alloted.

46. Bart Gottschalk - January 29, 2007

Here is an HTML/JavaScript implementation. I do these exercises for fun of them and because I’ve been “promoted” in my career to the point where I don’t get to write much code on the job. Doing exercises like these keeps the mind fresh and allows me to remember what it’s like to write code. Probably took about 5 minutes but that’s because I never try to remember syntax. I just look it up when I need it.

FizzBuzz

//

47. Bart Gottschalk - January 29, 2007

Oops. Let me try posting my JavaScript solution again:

var output = “”;

for( var i = 1; i

48. Tomas - January 29, 2007

Java code snippet:

for(int i=1;i0?toPrint:i);
}

Indeed, we would need to create a whole java class with a main method just to run this.
what a nasty language.

49. Tomas - January 29, 2007

Java code snippet (again):

for(int i=1;i<=100;i++) {
String toPrint=(i%3==0)?”Fizz”:”";
toPrint+=(i%5==0)?”Buzz”:”";
System.out.println(toPrint.size()>0?toPrint:i);
}

Indeed, we would need to create a whole java class with a main method just to run this.

(sorry the duplication. < and > are guilty)

50. Leonardo Herrera - January 30, 2007

Heh, can’t resist.

for(1..100){$t="";$t="Fizz"if!($_%3);$t.="Buzz"if!($_%5);$t||=$_;print"$t\n";}

51. Leonardo Herrera - January 30, 2007

…well, that was a 78 bytes solution that it is now buried under some weird CSS property. Alas.

52. StoneCypher - February 1, 2007

Jacob: most experienced coders use the XOR swap trick instead of allocating a new variable when swapping two machine primitives; it’s generally slightly faster and can be done in registers on the smallest of embedded machines.

If you see someone starting by allocating a third variable, you shouldn’t be hiring them.

53. George - February 2, 2007

Fizzbuzz in forth

: fizz? ( s — f ) 3 mod 0= ;
: buzz? ( s — f ) 5 mod 0= ;
: num? ( s — ) dup fizz? swap buzz? or 0= ;
: ?fizz ( s — ) fizz? if .” Fizz” then ;
: ?buzz ( s — ) buzz? if .” Buzz” then ;
: ?num ( s — ) num? if . then ;
: fizzbuzz ( s — ) dup ?fizz dup ?buzz dup ?num cr ;
: fizzbuzzes ( s — ) cr 1+ 1 do i fizzbuzz loop ;
100 fizzbuzzes
bye

it is fast well factored and with dumb logic no repeated values without return values it did not take two seconds because i was just learning to think forth, but this will

54. George - February 2, 2007

Also at the http://www.jwdt.com/~paysan/why-forth.html it says what discribes a bad programer

A few people expressed doubt if they are bad programmers, or if they shouldn’t try Forth because they might be part of what I considder “bad programmers”, so here’s a small test if you are a bad programmer. The more of the following answers you answer with “yes”, the worse you are. Don’t feel bad if you have a few “yes”, nobody’s perfect. I added also a few questions where a “no” should be quite sure:

* When you program, you wince at least once every minute, and not just because your tool crashed or displayed other bugs, but because you stare a the blank screen and don’t know what to enter.
* Extra points if you avoid this by pretenting to do “design” before coding, and you just produce tons of documents and UML diagrams without ever touching the keyboard and leaving the dirty work of implementing your designs to other people.
* When you have a problem, you invite for a meeting. The more people you invite here, the more points (and pointy hairs) you get.
* You think that a team of 10 programmers can solve tasks 10 times as complex or in one tenth of the time. Bonus points if you think 100 programmers scale as linear. Point dropped if you believe that because a set of 10 programmers contains one which is capable to outperform the average programmer by a factor of 10. Tell me how you prevent the others to mess up the job of the elite one.
* You always ask you what’s so funny about these “Dilbert” strips your coworkers put on their cubicle walls. Extra points if you follow the advices in “Dogberts top secret management handbook” when managing the dolts below you.
* You do programming for money; doing it as a hobby (for fun!) is something that only madmen do.
* You believe that programming can’t be self-taught, and titles are worth more than experience.
* You believe that your self-taught skills are better than anything you can learn at a university. Remove that point here if you believe that because you are the archcancellor of an elite university, and therefore know what you are talking about.
* You can’t grasp how this free software, or as you call it, “Lie-nuts” system came around, other than being either all lies, or created by nuts. Bonus points if you believe both.
* Your programs tend to become an unmaintainable mess of spaghetti code after 1000 lines (add bonus points if you reach that state earlier, reduce if you reach it later, “master of bloatware points” if your programs exceed 100klocs and are still maintainable). Extra points if your programs grow wild even after they have become unmaintainable.
* You didn’t know what to do with these rectangular Lego bricks when you were a child, and rather played with prefabricated toys.
* You think that one programming language (and maybe assembler) is enough to be a competent programmer. Bonus points if you believe that knowing a programming language isn’t necessary at all to be a competent programmer.
* You still believe that if you think hard enough you can produce correct non-trivial code without testing, though testing in the past always proved you wrong.

55. Patrick - February 5, 2007

Who says there is no ternary in python?

print “\n”.join([str(not (i%3 or i%5) and "FizzBuzz" or not i%3 and "Fizz" or not i%5 and "Buzz" or i) for i in range(1, 101)])

;-)

56. Ralph Miner - February 6, 2007

How disappointing that not one of the solutions fro Fizz Buzz started with writing acceptance tests.

57. What Do Programmers Do? » Continuous Learning - February 12, 2007

[...] Imran says many programmers can’t write code: [...]

58. Tragomaskhalos - February 13, 2007

The FizzBuzz program is a lovely little test, and I’ve now used it a couple of times myself in interviews. One guy got a “7/10″ from the business folks interviewing him, had 2+ years of Java on his CV, but couldn’t do this challenge at all – I mean he took a few minutes to even get out the loop opening, and that was a weird mishmash of while and for syntax.
I’d hate interviewers to dismiss this test as being too easy – in my experience it is genuinely astonishing how many candidates are incapable of the simplest programming tasks.

59. Cameron Kerr - February 24, 2007

Remove the leading ‘. ‘ on each line to use. Haskell is indent-sensitive

. module Main
. where
.
. main = do
. print $ map fizzbuzz [1..100]
.
. fizzbuzz x | x `mod` 15 == 0 = “FizzBuzz”
. | x `mod` 5 == 0 = “Buzz”
. | x `mod` 3 == 0 = “Fizz”
. | otherwise = show x

60. Cameron Kerr - February 24, 2007

And it still munges the text. Check my blog for what it should look like.

61. Paul - February 24, 2007

It’s a neat little test. I submitted it as a golfing challenge here:

http://golf.shinh.org/p.rb?FizzBuzz

Best solution so far is 50B of Perl. (Unfortunately, solutions are not viewable — or even saved.)

62. Coding Horror - February 27, 2007

Why Can’t Programmers.. Program?

I was incredulous when I read this observation from Reginald Braithwaite: Like me, the author is having trouble with the fact that 199 out of 200 applicants for every programming job cant write code at all. I repeat: they…

63. Syarzhuk - February 27, 2007

QBasic is easier :)

10 DATA “”, “”, “Fizz”, “”, “Buzz”, “Fizz”, “”, “”, “Fizz”, “Buzz”, “”, “Fizz”, “”, “”, “FizzBuzz”
20 DIM A$(15)
30 FOR I = 1 TO 15
40 READ A$(I)
50 NEXT I
60 FOR I = 1 TO 100
70 j = I MOD 15
80 IF A$(j) “” THEN PRINT A$(j) ELSE PRINT I
90 NEXT I

64. Cryptnotic - February 27, 2007

How about this one (just for fun):

int main()
{
int i;
for (i=1; i

65. Cryptnotic - February 27, 2007

Weak. Stupid less than signs.

int main()
{
int i;
for (i=1; i<=100; i++) {
switch(i % 15) {
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);
}
}
}

66. AlxShr - February 27, 2007

PHP::

for ($i=1;$

67. AlxShr - February 27, 2007

for ($i=1;$<101;$i++) {
if ($i%3==0)
echo “fuzz”;
if ($i%5==0)
echo “buzz”;
if ($i%3 && $i%5)
echo $i;
}

68. Patrik - February 27, 2007

.NET console application written in C#:

for (int i = 1; i

69. Patrik - February 27, 2007

Hmm. There might be something wrong with posting comments with the “less than” character. Anyway, here is the .NET console application solution written in C#:

for (int i = 1; i <= 100; i++)
{
Console.WriteLine((i % 3 == 0 && i % 5 == 0) ? “FizzBuzz” : ((i % 3 == 0) ? “Fizz” : (i % 5 == 0) ? “Buzz” : i.ToString()));
}

70. Brent Ashley - February 27, 2007

fizzbuzz.sh:

echo “1\n2\nfizz\n4\nbuzz\nfizz\n7\n8\nfizz\nbuzz\n11\nfizz\n13\n14\nfizzbuzz\n16\n17\nfizz\n19\nbuzz\nfizz\n22\n23\nfizz\nbuzz\n26\nfizz\n28\n29\nfizzbuzz\n31\n32\nfizz\n34\nbuzz\nfizz\n37\n38\nfizz\nbuzz\n41\nfizz\n43\n44\nfizzbuzz\n46\n47\nfizz\n49\nbuzz\nfizz\n52\n53\nfizz\nbuzz\n56\nfizz\n58\n59\nfizzbuzz\n61\n62\nfizz\n64\nbuzz\nfizz\n67\n68\nfizz\nbuzz\n71\nfizz\n73\n74\nfizzbuzz\n76\n77\nfizz\n79\nbuzz\nfizz\n82\n83\nfizz\nbuzz\n86\nfizz\n88\n89\nfizzbuzz\n91\n92\nfizz\n94\nbuzz\nfizz\n97\n98\nfizz\nbuzz\n”

71. lowly programmer - February 27, 2007

int
main(int argc,char *argv[])
{
int ii;

for(ii=0;ii++

72. A.D. - February 27, 2007

In T-SQL:

DECLARE @i int
SET @i = 1
WHILE (@i

73. Michael Letterle - February 27, 2007

I took a slightly different approach then Patrik, but similar:

for(int x=1; x

74. Michael Letterle - February 27, 2007

I took a slightly different approach then Patrik, but similar:

for(int x=1; x <= 100; ++x) { Console.WriteLine((x % 3 == 0 ? “Fizz” : “”) + (x % 5 == 0 ? “Buzz” : “”) + ((x % 3 != 0 && x % 5 != 0) ? x.ToString() : “”) ); }

75. Casual Observer - February 27, 2007

Another observation:

If the code is only three lines long, but is still hard to read, that’s also a bad sign.

If someone else wants to read your code, the simple version is better unless you have a very good reason (such as speed) for using peculiar shortcuts. Developer time is usually more important unless you have found a bottleneck.

Verbose code >> terse code 99% of the time. Some of you are showing off. Sorry, wouldn’t want you to work on my team.

76. matt - February 27, 2007

C’mon, everyone, you’re forgetting the master of all programming languages: Visual Basic for Applications (Excel in this case)! :)

Sub fizzbuzz()
For i = 1 To 100
If i Mod 3 = 0 Then
If i Mod 5 = 0 Then
Range(”A1″).Offset(i – 1, 0).Value = “fizzbuzz”
Else
Range(”A1″).Offset(i – 1, 0).Value = “fizz”
End If
Else
If i Mod 5 = 0 Then
Range(”A1″).Offset(i – 1, 0).Value = “buzz”
Else
Range(”A1″).Offset(i – 1, 0).Value = i
End If
End If
Next i
End Sub

77. Scott Hanselman's Computer Zen - February 27, 2007

You Can’t Teach Height – Measuring Programmer Competence via FizzBuzz

78. medbob - February 27, 2007

Took about 3 – 5 minutes because I couldn’t remember if the operator was DIV or MOD….

program Project1;

{$APPTYPE CONSOLE}

uses
SysUtils;
var i : Integer;
output : String;
begin
{ TODO -oUser -cConsole Main : Insert code here }
for I := 1 to 100 do
begin
Output := ”;
//Writeln(i,i mod 3);
if (i mod 3 = 0) then
Output := ‘Fizz’;
if (i mod 5 = 0) then
if (i mod 3 = 0) then
output := ‘Fizz-Buzz’
else
output := ‘Buzz’
else
if Output = ” then
Output := IntToStr(i);

Writeln(Output);
end;
Read(i);

end.

79. Fratm - February 27, 2007

PERL:
while ($i

80. gorgan - February 27, 2007

You just can’t beat the clean look of perl!

print$_%3?$_%5?$_:’Buzz’:$_%5?’Fizz’:'FizzBuzz’,”\n”for 1..100;

81. Fratm - February 27, 2007

I used an less than = but couldnt post it.. so changed it a little.

while ($i != 101)
{
if ($i%3==0) { $out= “fizz”; }
if ($i%5==0) { $out .= “buzz”; }
if ($out) {print “$out \n”} else { print “$i\n”; }
++$i;
undef ($out);
}

82. rascunho » Seção de dados do blog » links for 2007-02-27 - February 27, 2007

[...] Using FizzBuzz to Find Developers who Grok Coding « Imran On Tech Write a program that prints the numbers from 1 to 100. 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”. (tags: tickletux.wordpress.com 2007 at_tecp Fizz Buzz FizzBuzz programming test) [...]

83. Too Embarrassed - February 27, 2007

VB 6 Immediate window:

for x = 1 To 100: Debug.Print switch(x Mod 3 = 0,”fizz”,x Mod 5 = 0,”buzz”,x Mod 15 = 0,”fizzbuzz”,True,x):next

84. Shabaka - February 27, 2007

These programming tests aren’t real world situations anyway. Every scientist knows that an object behaves differently under observation. Job interviews are already tense situations. Then to have to write code with someone breathing down your neck…I don’t think testing like this is a good way to screen out candidates. For one thing, if you are hiring a web developer, chances are s/he will be working online. What’s wrong with using Google? We’ve gotten to a point where we don’t have to recreate the wheel. What purpose does FizzBuzz serve in the real world? In my CompSci class, the prof said that programmers are lazy. If the problem has already been solved, whats the point so sweating about it?

85. Tim Balbekov - February 27, 2007

I’m 15 and have never taken a programming class. Seven minutes in C:

#include “stdio.h”

int main() {
int i;
for(i = 1; i

86. LowJo - February 27, 2007

Alright smart guys.

How about some OO? ;)

using System;

internal class Program
{
private static void Main()
{
for( int i = 1; i

87. Tim Balbekov - February 27, 2007

#include “stdio.h”

int main() {
int i;
for(i = 1; i LESS_THAN_GETS_FILTERED 100; i++) {
if( (i % 3 == 0) && (i % 5 == 0))
printf(”FizzBuzz\n”);
else if(i % 3 == 0)
printf(”Fizz\n”);
else if(i % 5 == 0)
printf(”Buzz\n”);
else printf(”%i\n”, i);
}

return 1;
}

88. Eric - February 27, 2007

my perl version (59 chars, borrowing some ideas from previous posts):
print+($_%3?”":”Fizz”).($_%5?”":”Buzz”)||$_,”\n”for 1..100;

89. Andy LeClair - February 27, 2007

Freshman at Northeastern University. 5 minutes in Pretty Big Scheme (PLT’s MzScheme (which includes R5RS) and the HTDP.org teaching languages)

;; fizzbizz: Number -> String
;; prints out the numbers from 0 to [sub1 n], fizz on a mult. of 3,
;; bizz on 5, and fizzbizz on both
(define (fizzbizz n)
(build-list n (lambda (x)
(cond
[(and (= 0 (modulo x 3))
(= 0 (modulo x 5))) "fizzbizz"]
[(= (modulo x 3) 0) "fizz"]
[(= (modulo x 5) 0) "bizz"]
[else x]))))

90. Andy LeClair - February 27, 2007

follow that up with:

(fizzbizz 100) or up to whatever you please.

91. otli4nitsa and keda - February 27, 2007

in perl… 67b :) paul, how’d you do 50b? plz post the code.

for(1..100){print ” “,$_%3?$_%5?$_:’fizz’:$_%5?’buzz’:'fizzbuzz’;}

92. Ayende @ Rahien - February 27, 2007

If Program I Can’t, Programmer Am I?

If Program I Can’t, Programmer Am I?

93. Steve - February 27, 2007

>To Shabaka:
>These programming tests aren’t real world situations anyway.

You’re right. These programming tests are far simpler than real world situations. If you can’t hack a simple contrived problem like FizzBuzz, it’s very likely you can solve a real world problem.

94. Dan - February 27, 2007

Javascript…

function FizzBuzz()
{
var strAlert=”";
for(var i=1; i

95. Dan - February 27, 2007

Javascript:
(I cant believe they don’t escape your input…)

function FizzBuzz()
{
var strAlert="";
for(var i=1; i<=100; i++)
{
strAlert += (i%3==0)?"Fizz":"";
strAlert += (i%5==0)?"Buzz":"";
strAlert += (i%3!=0 && i%5!=0)?i:"";
strAlert += ", "
}
alert(strAlert.substring(0, strAlert.length-2));
}

96. JimGee - February 27, 2007

I would happy if they can do this.

/* Comments about program go here*/
#include “stdio.h”
int main(int argc, char* argv[])
{
int i;
for(i=1; i

97. Don Beal - February 27, 2007

What a great post…

I have been writing code for about 20 years now, it’s amazing how in the past 10 nobody wants anything but VB for in-house stuff (mostly for TTM reasons) but this is a tremendous example of how there are a million ways to accomplish the same thing in 100 different languages.

I recently went out to dinner with a fellow consultant and we had this discussion about how new programmers know the latest .NET and nothing else and it is just pitiful how they have no foundation whatsoever. If it weren’t for Randy Birch I doubt they would ever pass a mid-term. I think that is the byproduct of making languages easier to read/write.

A lot of people can paint a house, but I wouldn’t call them all house painters.

Again, awesome thread.

98. JimGee - February 27, 2007

‘/* Comments about program go here*/
#include “stdafx.h”
int main(int argc, char* argv[])
{
int i;
for(i=1; i

99. JimGee - February 27, 2007

I would happy if they can do this.

/* Comments about program go here*/
#include “stdafx.h”
int main(int argc, char* argv[])
{
int i;
for(i=1; i&lt 101; i++)
{
printf(”%d “,i);
if(i % 3 ==0)
printf(”Fizz”);
if(i % 5 == 0)
printf(”Buzz”);
printf(”\n”);
}
return 0;
}

100. VOID - February 27, 2007

def FizzBuzz():
for i in range(1,101):
n=i%15
if(n==0): print “FizzBuzz”
elif(n in [3,6,9,12]):print “Fizz”
elif(n in [5,10]):print “Buzz”
else: print i

FizzBuzz()

Had to be original.

101. dumb - February 27, 2007

/

102. rob - February 27, 2007

the real test should be to leave a coding example and have the < and > show up ;)

103. imdumb - February 27, 2007

help me I’m dumb
/

104. Pat - February 27, 2007

I’ve done FizzBuzz in C language in 7 minutes and swap variables in 20 seconds. I think this is not bad and also not impressive. But these questions are too much hazardous. Too much synthetic to bring some guy down at the interview. Personally I’ve been two times a victim of that smart questions that I have not passed. However I consider myself as above average skilled programmer.

105. Steve - February 27, 2007

To Pat:
>Personally I’ve been two times a victim of that smart questions
>that I have not passed. However I consider myself as above
>average skilled programmer.

How do you know you’re an above average skilled programmer? There literally billions of dumb people roaming this earth who are deluded they are very intelligent though reality tells a different story. What makes you think you’re immune to being deluded about your own skills and intelligence?

Ask yourself this: Why did it take you 7 minutes to write FizzBizz? Do you type really slow? Did you have to fix bugs? Did you have to fix compiler errors? Did you know right away to use the mod operator?

Don’t you think if a person has trouble with a problem like this, they might do a poor job at solving real world problems with which the complexity of the problems are orders of magnitude more complicated?

106. robby - February 27, 2007

LoL its funny cause all these guys are like bragging that they can code this program by putting the code in their comment..

BUT ITS ALL WRONG

if i = 15 it would print, FIZZBUZZ
FIZZ
BUZZ
resulting it occurring twice..
cause you have no ‘continue’ after your if statement that checks for 3 and 5

it would also make more sense to check if it is divisible by 15 rather than 3 && 5

Hopeless.. im telling your boss to outsource your job to India.

107. Ray - February 27, 2007

in IL:

.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 120 (0×78)
.maxstack 2
.locals init ([0] int32 i,
[1] string ‘value’,
[2] bool CS$4$0000)
IL_0000: nop
IL_0001: ldc.i4.1
IL_0002: stloc.0
IL_0003: br.s IL_0065
IL_0005: nop
IL_0006: ldloca.s i
IL_0008: call instance string [mscorlib]System.Int32::ToString()
IL_000d: stloc.1
IL_000e: ldloc.0
IL_000f: ldc.i4.3
IL_0010: rem
IL_0011: brtrue.s IL_001e
IL_0013: ldloc.0
IL_0014: ldc.i4.5
IL_0015: rem
IL_0016: ldc.i4.0
IL_0017: ceq
IL_0019: ldc.i4.0
IL_001a: ceq
IL_001c: br.s IL_001f
IL_001e: ldc.i4.1
IL_001f: stloc.2
IL_0020: ldloc.2
IL_0021: brtrue.s IL_002d
IL_0023: nop
IL_0024: ldstr “FizzBuzz”
IL_0029: stloc.1
IL_002a: nop
IL_002b: br.s IL_0059
IL_002d: ldloc.0
IL_002e: ldc.i4.3
IL_002f: rem
IL_0030: ldc.i4.0
IL_0031: ceq
IL_0033: ldc.i4.0
IL_0034: ceq
IL_0036: stloc.2
IL_0037: ldloc.2
IL_0038: brtrue.s IL_0044
IL_003a: nop
IL_003b: ldstr “Fizz”
IL_0040: stloc.1
IL_0041: nop
IL_0042: br.s IL_0059
IL_0044: ldloc.0
IL_0045: ldc.i4.5
IL_0046: rem
IL_0047: ldc.i4.0
IL_0048: ceq
IL_004a: ldc.i4.0
IL_004b: ceq
IL_004d: stloc.2
IL_004e: ldloc.2
IL_004f: brtrue.s IL_0059
IL_0051: nop
IL_0052: ldstr “Buzz”
IL_0057: stloc.1
IL_0058: nop
IL_0059: ldloc.1
IL_005a: call void [mscorlib]System.Console::WriteLine(string)
IL_005f: nop
IL_0060: nop
IL_0061: ldloc.0
IL_0062: ldc.i4.1
IL_0063: add
IL_0064: stloc.0
IL_0065: ldloc.0
IL_0066: ldc.i4.s 100
IL_0068: cgt
IL_006a: ldc.i4.0
IL_006b: ceq
IL_006d: stloc.2
IL_006e: ldloc.2
IL_006f: brtrue.s IL_0005
IL_0071: call string [mscorlib]System.Console::ReadLine()
IL_0076: pop
IL_0077: ret
} // end of method Program::Main

108. Daruku - February 27, 2007

// c#

class FizzBuzz
{
static void Main(string[] args)
{
for (int i = 1; i

109. C Is A Write-Only Language - February 27, 2007

You suckas. In APL I can solve either problem in one character: a

I’ll take my job offer now, thanks.

110. DeathToSpam - February 27, 2007

ASP/VBScript, complete with purdy output formatting:

” & vbNewLine
Next %>

111. DeathToSpam - February 27, 2007

ASP/VBScript, complete with purdy output formatting:

Dim iLoop, bIsMultipleOfThree, bIsMultipleOfFive, sOutput

For i = 1 to 100
bIsMultipleOfThree = (i MOD 3 = 0)
bIsMultipleOfFive = (i MOD 5 = 0)

If (i ” & vbNewLine
Next

112. DeathToSpam - February 27, 2007

Tried to post, but characters got all truncated after submitting. :( Oh well.

113. Lumpio- - February 27, 2007

I can’t believe nobody thought of

for i in range(1, 101): print [i, "Fizz", "Buzz", "FizzBuzz"][int(i % 3 == 0) + int(i % 5 == 0) * 2]

114. Leonardo Herrera - February 28, 2007

Bah, couldn’t beat the 49 bytes mark (mine is 54 bytes).
print$_%3?$_%5?$_:”":Fizz,$_%5?”":Buzz,”\n”for 1..100;

115. Leonardo Herrera - February 28, 2007

(And I keep marveled at our capacity to intentionally miss the point.)

116. Marek Pułczyński - February 28, 2007

Just for completness – BASH oneliner (dumbly assuming modulo is as expensive as comparison)

for x in `seq 100` ; do if [ `expr $x % 15` -eq 0 ] ; then echo FizzBuzz; elif [ `expr $x % 3` -eq 0 ]; then echo Fizz; elif [ `expr $x % 5` -eq 0 ]; then echo Buzz; else echo $x; fi; done

117. Jason - February 28, 2007

A little more convoluted than the examples above in Python, but still (fairly) followable:

print ‘\n’.join([{(False, False): y[-1], (True, False): “Fizz”, (False, True): “Buzz”, (True, True): “FizzBuzz”}[y[0]] for y in [((x%3==0, x%5==0), str(x)) for x in range(1, 101)]])

118. mobmash blog » Blog Archive » links for 2007-02-28 - February 28, 2007

[...] Using FizzBuzz to Find Developers who Grok Coding « Imran On Tech (tags: programming interview) [...]

119. bumSki - February 28, 2007

// in C++
int main()
{
for (int count = 1; count

120. Matt - February 28, 2007

This is the shortest way I could think of doing it in C++. Of course, the layout is absolutely horrid (no whitespace, etc) but it’s short and it works:

#include
int main()
{
for(int i=1;i

121. MrMajestyk - February 28, 2007

For i As Integer = 1 To 100
If i Mod 3 = 0 Then
lblSolution.Text &= “Fizz” & vbCrLf
ElseIf i Mod 5 = 0 Then
lblSolution.Text &= “Buzz” & vbCrLf
ElseIf i Mod 3 = 0 And i Mod 5 = 0 Then
lblSolution.Text &= “FizzBuzz” & vbCrLf
Else
lblSolution.Text &= i & vbCrLf
End If

Next

122. Thomas Moitie - February 28, 2007

“Want to know something scary ? – the majority of comp sci graduates can’t.”

I’m 17, self-taught at php. A language in which I came up with a solution within 1 minute. I am utterly astounded if this statement is true

123. someone tired of writing code but loving of doing it also - February 28, 2007

after 15 years of c++ experience.
i wonder why you check three conditions for FizzBuzz thing!
one for fizz, one for buzz, and another for fizzbuzz..
wouldnt it be reasonable to use a boolean to control not to write the number. but only checking if it is a modul of 5 or 3. and after the each loop, feeding the line.

one thing is favorable, you should write a code to be extended easily in the future.

124. Thomas Messier - February 28, 2007

One test we used to administer for web developers was ask them to code a simple calendar. We gave them plenty of time, along with all the reference manuals. Lots of people couldn’t do it in 30 minutes.

125. Carl - February 28, 2007

What? No one’s tried to use C++ templates to compute FIZBUZ at compile time instead of at runtime.

126. Syed Muhammad - February 28, 2007

programming requires a little bit of talent and some passion of PROBLEM SOLVING. probably that’s why they can’t write the code. no problem solving skills.

127. Procyon - February 28, 2007

windows batch file:

@echo off
set count=1
:loop
set div3=%count%
set div5=%count%
:loop3
set /a div3 -= 3
if not %div3% leq 0 goto :loop3
:loop5
set /a div5 -= 5
if not %div5% leq 0 goto :loop5
if %div3%==0 (
if %div5%==0 (
echo fizzbuzz
) else (
echo fizz
)
) else (
if %div5%==0 (
echo buzz
) else (
echo %count%
)
)
set /a count += 1
if %count% lss 100 goto :loop

128. Unmaintainable Code - February 28, 2007

#include
int main(){int i;for(i=1;101>i;++i)printf(i%15?i%3?i%5?”%d\n”:
“Buzz\n”:”Fizz\n”:”FizzBuzz\n”,i);}

129. Anonymous - February 28, 2007

main(i){for(i=0;i

130. Matt - February 28, 2007

Here’s the main part of my code since my post was clipped for some reason:

std::cout

131. GS - February 28, 2007

Since everyone else is posting their solution:

#FIZZBUZZ.PY
for i in range(1,101):
flag = True
num = []
if i % 3 == 0:
num.append(”Fizz”)
flag = False
if i % 5 == 0:
num.append(”Buzz”)
flag = False
num = ”.join(num)
if flag:
num = str(i)
print “%s\n” % (num),

132. Trey Marcus - February 28, 2007

I’m not at all surprised at this because the interviewer is apparently asking a person to use a piece of paper or whiteboard to write a computer program. This is a completely foreign environment for most programmers I know and under the stress of an interview I am not at all surprised that most programmers would have trouble with such a task.

If you want to know if a person can architect a solution to a FizzBuzz style problem then I think its fine to ask them how they might go about solving it. Asking someone to write a computer program on a piece of paper seems a bit assinine and I think such interview tactics say far more about the interviewer than the interviewee.

If you want to test a person’s programming abilities… great. Give him a computer and a problem and leave him to work as he normally would to find a problem even if its just a few minutes.

133. Bob On Development » The Crisis of Programmer Competence - February 28, 2007

[...] In fact some interviewers have taken to screening all applicants early with some trivial programming problem like the FizzBuzz Question. [...]

134. shoebappa - February 28, 2007

Jacob, I’d seen the opposite question, to swap two variables without using a third…

$x = 5;
$y = 11;

$x = $x + $y; // 5+11 = 16
$y = $x – $y; // 16-11 = 5
$x = $x – $y; // 16-5 = 11

guess it only works with numbers, but using a third variable is the obvious solution, it’s unfortunate that you could weed anyone out with that question…

135. Jason - February 28, 2007

Common Lisp, format-style:
(loop for i from 1 to 100
do (format t “~A ~:[~;Fizz~]~:[~;Buzz~]~%” i (zerop (mod i 3)) (zerop mod i 5))))

136. test - February 28, 2007
137. test - February 28, 2007

< >

138. Exec - February 28, 2007

XSL version
=======

<?xml version=”1.0″ encoding=”UTF-8″?>
<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” xmlns:fo=”http://www.w3.org/1999/XSL/Format”>

<xsl:template match=”/”>
<xsl:call-template name=”fizzLogic”>
<xsl:with-param name=”iCount” select=”‘1′”/>
</xsl:call-template>
</xsl:template>

<xsl:template name=”fizzLogic”>
<xsl:param name=”iCount”/>

<xsl:if test=”$iCount &lt; 101″>
<xsl:choose>
<xsl:when test=”$iCount mod 3=0 and $iCount mod 5 = 0″>FizzBuzz</xsl:when>
<xsl:when test=”$iCount mod 3=0″>Fizz</xsl:when>
<xsl:when test=”$iCount mod 5=0″>Buzz</xsl:when>
<xsl:otherwise><xsl:value-of select=”$iCount”/></xsl:otherwise>
</xsl:choose>

<xsl:call-template name=”fizzLogic”>
<xsl:with-param name=”iCount” select=”$iCount+1″/>
</xsl:call-template>

</xsl:if>
</xsl:template>

</xsl:stylesheet>

139. The Mu » Blog Archive » Programmers that can’t program - February 28, 2007

[...] an aside, I gave the FizzBuzz problem a shot too.  I included my result below (it took me almost twenty minutes because I [...]

140. Sougent - February 28, 2007

I’m waiting for the solution in COBOL…….

141. Vincent McNabb - February 28, 2007

In JavaScript:

for(i = 1; i < 101; i++) {
  if(i%3==0) document.write("Fizz");
  if(i%5==0) document.write("Buzz");
  if(!((i%3==0)|(i%5==0))) document.write(i);
  document.write("<br>");
}

Basic

for i = 1 to 100
  if i mod 3 = 0 then print "Fizz"
  if i mod 5 = 0 then print "Buzz"
  if i mod 3 > 0 and i mod 5 > 0 then print str$(i)
next

142. Thomas Chapin - February 28, 2007

I wonder if you replace the lesser than symbol with the html escaped version, it will work? Testing now: <

143. Thomas Chapin - February 28, 2007

Ok. Cool. It looks like that worked.

Here’s my version done in javascript:

<script>

for(i=1; i<101; i++){

   if(i%15==0){
      document.write(”FizzBuzz<BR>”);
   }else if(i%5==0){
      document.write(”Buzz<BR>”);
   //
   }else if(i%3==0){
      document.write(”Fizz<BR>”);
   }else{
      document.write(i+”<BR>”);
   }

}

</script>

144. Thomas Chapin - February 28, 2007

whoops I left two slashes in there on accident (I was going to put comments in there but decided to remove them)

145. Ian - February 28, 2007

“I’m waiting for the solution in COBOL…”

something like (I don’t have a compiler to hand and it’s been a while):

PERFORM VARYING Count FROM 0 BY 1 UNTIL Count > 99
COMPUTE Three-Mod = FUNCTION MOD (Count, 3).
COMPUTE Five-Mod = FUNCTION MOD (Count, 5).
IF Three-Mod = 0 AND Five-Mod = 0 THEN
DISPLAY “FizzBuzz”
ELSE
IF Three-Mod = 0 THEN
DISPLAY “Fizz”
ELSE
IF Five-Mod = 0 THEN
DISPLAY “Buzz”
ELSE
DISPLAY Count
END-IF
END-IF
END-PERFORM

But as the nested IF’s suck, with an EVALUATE something like this:

PERFORM VARYING Count FROM 0 BY 1 UNTIL Count > 99
COMPUTE Three-Mod = FUNCTION MOD (Count, 3).
COMPUTE Five-Mod = FUNCTION MOD (Count, 5).
EVALUATE Three-Mod ALSO Five-Mod
WHEN 0 ALSO 0 DISPLAY “FizzBuzz”
WHEN 0 ALSO >0 DISPLAY “Fizz”
WHEN >0 ALSO 0 DISPLAY “Buzz”
WHEN >0 ALSO >0 DISPLAY Count
END-EVALUATE
END-PERFORM

146. flickrhoneys - February 28, 2007

Grok coding is one of my many hobbys, but i need someone to explain it to me :(

147. Fahd Mirza - February 28, 2007

Reading this thread was a splendid education

148. eric - February 28, 2007

indeed scary

that FizzBuzz problem should take 1-2 minutes max for an experienced developer.

Any more directly presents hesitance and a lack of skill. Unable for someone to answer it should mean that they chose a wrong path and should never have become developers.

149. eric - February 28, 2007

I cannot help noticing how simple this program is, and how many people have posted their solutions here, (trying of course to give a quick and clever minimalistic solution)

I haven’t read all the replies above me, and I am not surprised to found at least 3 solutions which do not work.

Not to name any but some solutions above print “Fizz Buzz FizzBuzz” when they find multiples of 3 and 5.

Being quick and rushing are not the same thing.

150. Alex - February 28, 2007

Can’t forget C# with a little LINQ…

foreach (string s in Sequence.Range(1,100).Select<int,object>(i => ((i%15)==0) ? “FizzBuzz” : ((i%3)==0) ? “Fizz” : ((i%5)==0) ? “Buzz” : i.ToString())) Console.WriteLine(s);

151. Ross Hawkins - February 28, 2007

IBM Lotus Notes @Function FizzBuzz

@For(n := 1; n <= 100; n := n + 1; output := output + @If(@Modulo( n ; 3 ) = 0 & @Modulo( n ; 5 ) = 0; “FizzBuzz”;@Modulo( n ; 3 ) = 0; “Fizz”; @Modulo( n ; 5 ) = 0; “Buzz” ; @Text(n) ));output;

or

@For(n := 1; n <= 100; n := n + 1;tmp := @If(@Modulo( n ; 3 ) = 0; “Fizz”; “”);tmp := tmp + @If(@Modulo( n ; 5 ) = 0; “Buzz”; “”);output := output + @If(@Length(tmp) =0; @Text(n); tmp ));output

Add a @Newline in there for readability if you wish. The great thing about the IBM/Lotus solution is that there’s hardly anyone out there who’s going to bother to test it.

152. Yuri - February 28, 2007

Someone wrote:

def FizzBuzz():
for i in range(1,101):
n=i%15
if(n==0): print “FizzBuzz”
elif(n in [3,6,9,12]):print “Fizz”
elif(n in [5,10]):print “Buzz”
else: print i

FizzBuzz()

Had to be original.

Hehe, nice!

153. Reality Me » And they call themselves programmers… - February 28, 2007

[...] he made a very good post asking "Why can’t programmers.. Program?" He referenced Imran on Tech who uses a simple problem to figure out if his prospective candidates can code. Imran also has good [...]

154. News Flash: Tech Interviews Don’t Work at mark++ - February 28, 2007

[...] Imram [...]

155. The Mu » Blog Archive » Blogosphere abuzz over FizzBuzz - February 28, 2007

[...] of traffic was created by Imran’s original post, Reg Braithwaite’s comment, and Jeff Atwood’s followup. All over the blogosphere, eager [...]

156. silentflute » Programmers can’t program? - February 28, 2007

[...] Using FizzBuzz to Find Developers who Grok Coding [...]

157. slimCODE, aka Martin Plante : Comment reconnaître un bon développeur - February 28, 2007

[...] à un poste de développeur est recommencé depuis un billet de Imran qui se sent obligé de mettre la barre très basse lors d’entrevues. Il propose l’implémentation d’un jeu d’enfant appelé FizzBuzz (tout bon [...]

158. Dilbert - February 28, 2007

There is some major flaws in this testing approach with any corporate programmer. First of all, you didn’t give him any time to discuss the requirements with analysts and end users, nor did you present him with use cases, workflows, or activity diagrams. You didn’t bother to explain unit test plans or QA bug tracking, nor did you even have the courtesy of scheduling five meetings to review specs, user interfaces, budgets, or schedules! You are also going to need to provide 45 minutes of time for the programmer to check his daily e-mail from his 5 supervisors who want to know what he is doing. AND YOU WONDER WHY THEY FAIL THE TEST???!!!

159. anon - March 1, 2007

Didn’t know about the MOD operator, so had to try a different method:

Sub FizzBuzz()

t3 = 0
t5 = 0

For i = 1 To 100

t3 = t3 + 1
t5 = t5 + 1
Number = False

If t3 = 3 And t5 5 Then
Cells(i, 5) = “Fizz”
t3 = 0
Number = True
End If

If t5 = 5 And t3 3 Then
Cells(i, 5) = “Buzz”
t5 = 0
Number = True
End If

If t3 = 3 And t5 = 5 Then
t3 = 0
t5 = 0
Cells(i, 5) = “FizzBuzz”
Number = True
End If

If Number = False Then
Cells(i, 5).Value = i
End If
Next

End Sub

160. Nick - March 1, 2007

In Prolog…

start :- fizz_buzz(1,100).

fizz_buzz(Lo,Hi) :-
Lo <= Hi ,
output(Lo) ,
Next is Lo+1 ,
FizzBuzz(Next,Hi).
FizzBuzz.

output( N ) :-
R3 is N mod 3 ,
R5 is N mod 5 ,
text( R3 , R5 , N , T ) ,
write(T) ,
nl.

text( 0 , 0 , N , N ).
text( _ , 0 , _ , ‘Fizz’ ).
text( 0 , _ , _ , ‘Buzz’ ).
text( _ , _ , _ , ‘FizzBuzz’ ).

161. The FizzBuzz Fizz And Weak Programmers on iface thoughts - March 1, 2007

[...] rightly points out that a lot of programmers, who talk well about programming, cannot actually code. Jeff Atwood follows up with his views on it. My experience has been a little different, when I got [...]

162. Solving FizzBuzz Problem | FuCoder.com - March 1, 2007

[...] quoted Irman’s FizzBuzz question, a trivial programming problem but surprisingly has stumbled many job applicants. Here is the [...]

163. Pete - March 1, 2007

I’m not really much of a programmer, but here’s my Fizzbuzz in C++:

#include
using namespace std;

int main(){
int x=0;
do {
x++;
cout

164. Pete - March 1, 2007

^that broke….

#include
using namespace std;

int main(){
int x=0;
do {
x++;
cout

165. Pete - March 1, 2007

……

166. Scorpyosis - March 1, 2007

You will never hire me, in spite of I can swap two variables (a,b)without creating a third variable :
a = a + b
b = a – b
a = a – b

>>> In respond to this comment :
3. Jacob – January 24, 2007
Want another good filter? This surprised me, but turns out to be a good indication of whether someone has actually ever programmed before.

Ask: show me (on paper, but better on a whiteboard) how you would swap the values of two variables.

If they don’t *start* with creating a third variable, you can pretty much write that person off. I’ve found that I can cut a third to half my (admittedly at that point unscreened) applicants with that question alone.

167. Don - March 1, 2007

“Dilbert (Feb 28)”, funny point, don’t forget to mention the one guy that is neither engineer nor developer somehow getting involved and insisting on changing the scope of the project every third minute.

;-?

168. A ver si no sabemos programar… « Para bellum - March 1, 2007

[...] autor al que se refiere es Imran, que está rechazando a montañas de programadores que no saben escribir un simple programa. Después de unas cuantas pruebas y errores descubrí que a las personas que se pelean con el [...]

169. Mike Nolan - March 1, 2007

81 characters in PHP but I’m sure it can be reduced a little:

for($i=1;$i

170. Dave - March 1, 2007

– in oracle plsql
begin
dbms_output.enable;
for i in 1..100
loop
if mod(i,3)=0
then dbms_output.put_line(’Fizz’);
elsif mod(i,5) =0
then dbms_output.put_line(’Bizz’);
elsif mod(i,3)=0 and mod(i,5)=0
then dbms_output.put_line(’FizzBizz’);
else
dbms_output.put_line(i);
end if;
end loop;
end;

171. Dave - March 1, 2007

– correction…plsql
begin
dbms_output.enable;
for i in 1..100
loop
if mod(i,3)=0 and mod(i,5)=0
then dbms_output.put_line(’FizzBizz’);
elsif mod(i,3)=0
then dbms_output.put_line(’Fizz’);
elsif mod(i,5) =0
then dbms_output.put_line(’Bizz’);
else
dbms_output.put_line(i);
end if;
end loop;
end;

172. Kisara - March 1, 2007

The sad part about this is that it took me about 3 minutes to write.

And I’m 12.

173. C.F. - March 2, 2007

What about this?

public class FizzBuzz {

static final int MAX_NUM = 100;

public static void main(String[] args) {

String str;

for(int i = 1; i

174. steve - March 2, 2007

My first python program. I have been wanting to learn Python so I thought I would install it and try FizzBuzz on for size. I see some other Python examples but this one is a little different. How bad is it?

for x in range(1, 101): # needs to be 101 to include 100 in the loop
out = “” # set reset output
if x%3 == 0: # x evenly divisible by 3
out = ‘Fizz’ # yes
if x%5 == 0: # x evenly divisible by 5
out = out + ‘Buzz’ # yes
if out == “”: # is out null
print x # yes print x
else:
print out # no print out

175. Brian Adkins - March 2, 2007

68 bytes in Ruby

1.upto(100){|i|puts”FizzBuzz#{i}”[i%3==0?0:i%5==0?4:8,i%15==0?8:4]}

176. Scott Hanselman's Computer Zen - Hanselminutes Podcast 53 - Hiring and Interviewing Engineers - March 2, 2007

[...] Using FizzBuzz to Find Developers who Grok Coding (mgx) Don’t Overthink FizzBuzz (mh0) On Interviewing Programmers (mh3) Why Can’t Programmers.. Program? (mgy) Programming Jokes compiled by Raganwald (mh1) The Guerrilla Guide to Interviewing (version 3.0) (mh4) You Can’t Teach Height – Measuring Programmer Competence via FizzBuzz (mgz) What Great .NET Developers Ought To Know (More .NET Interview Questions) (mh2) [...]

177. Brian Adkins - March 2, 2007

Oh man, shaved off 3 bytes :)

1.upto(100){|i|puts”FizzBuzz#{i}”[i%3

178. Brian Adkins - March 2, 2007

1.upto(100){|i|puts”FizzBuzz#{i}”[i%3<1?0:i%5<1?4:8,i%15<1?8:4]}

179. James - March 2, 2007

Response.Write(”1″)
Response.Write(vbcrlf)
Response.Write(”2″)
Response.Write(vbcrlf)
Response.Write(”Fizz”)
Response.Write(vbcrlf)
Response.Write(”4″)
Response.Write(vbcrlf)
Response.Write(”Buzz”)
Response.Write(vbcrlf)
Response.Write(”Fizz”)
Response.Write(vbcrlf)
Response.Write(”7″)
Response.Write(vbcrlf)
Response.Write(”8″)
Response.Write(vbcrlf)
Response.Write(”Fizz”)
etc.

180. Spacecadet - March 2, 2007

Having read almost every comment on this story I’d probably sack the lot of you.
Where’s the input parameters?
Where’s the modularity?
What happens if in 6 months time the requirements change to 4 and 7 being the fizzbuzz numbers?
What happens when the program needs to be used by the french team who need le fizz le buzz?
What happens when the program is up-scaled to cover 0-1000

181. Marillionfan - March 2, 2007

And I wouldnt hire any of you in the first place.

Wasting my companies time on a technical pissing contest.

You’re Fired.

182. Brian Adkins - March 2, 2007

Ok, down to 64 bytes in Ruby, but I think I’ve reached an impasse :(

1.upto(?d){|i|puts”FizzBuzz#{i}”[i%3<1?0:i%5<1?4:8,i%15<1?8:4]}

183. Bruce - March 2, 2007

you guys are such nerds. perhaps this sort of question makes sense for grad, but to be honest, it’s useless. show me the data on “passing silly programming questions to good engineers”. Sure they need to understand software, but this sort of micro-rubbish is somewhat irrelevant, certainly in terms of the people I’d hire.

184. Jake Cohen - March 2, 2007

@SpaceCadet,

You forgot to ask if it’s Y10K compliant, in how many languages its documentation is available, and whether it supports TWAIN-compliant scanners.

185. murty - March 2, 2007

I think these are all good observations but we need to keep in mind that we may encounter a programmer who is smarter than us.

Take for example, Jacob’s test – swap the value of 2 variables. He expects the programmer to start with a 3rd variable but one can achieve the desired result without a 3rd variable.

a = 11;
b= 12;

a = a XOR b; //a = 7
b = a XOR b; // b = 11
a = a XOR b; // a = 12

Besides, software engineering is much more than programming. And you all know that.

186. Mark Miller - March 3, 2007

I’ve been surprised in the past at what I hear people who interview for programing positions can’t do. I found this through Giles Bowkett’s blog, and he’s right. If you can’t solve FizzBuzz in a few seconds in your head, you’re not that great. In fact, if memory serves me I think I solved a programming problem like this when I was in high school 20 years ago. To heck with a CS degree. This is elementary stuff.

It is possible for programmers to overthink themselves into a hole, when in fact the problem is very simple. I’ve done it in the past. The few times I did it in an interview was when I was young and naive, and I was trying to impress the interviewer… So that could explain some of the times when it took 15 minutes for someone. Still, do you want to hire someone who overthinks problems?

Try this one on for size. When I got out of college with a CS degree I interviewed at a small company. They asked me this question:

Write a C program that takes an integer and converts it to a string, without using printf(), or any printf() variant. I might’ve been able to use printf() to output the result string. puts() works too. The integer had at least 2 or 3 digits in it, and was pre-assigned to an int variable. I had the solution coded and running in about 5 minutes. They told me that several people they interviewed could not solve it at all.

If anyone wants to try it in other languages, be my guest. The key to the problem is to not use library functions to solve it, only operators native to the language.

I’ve had problems posed to me at interviews that were harder than this, which stumped me, using higher math, or I just didn’t understand the question.

187. Mark Miller - March 3, 2007

Referring to the C problem I posed:

No fair using itoa() either!

188. spacecadet - March 3, 2007

@Jake Cohen
I detected a hint of sarcasm in your reply.

The point I’m trying to make is, I don’t care if it take a programmer 5 minutes or an hour to come up with the solution. What I want to know is, will the programmer apply some professionalism to the problem. Will he take into account changing requirements, will he make sure that basic changes can be made without the need for someone to go digging through code.
Its one thing being some geek hacker, its something else completely to be a professional about your job and to try and engineer your solution in a manner that is fit for the task which the problem solver may not have even seen coming. As a professional YOU are supposed to be experienced, YOU should be able to see how your solution may be needed for many other similar queries. YOU should be able to see past the obvious question asked.
As far as I’m concerned, the geek hackers have their use, but, if comparing building an apartment block to building software, everyone who has posted here has very good experience of laying bricks but no appreciation of how the building needs to be actually used by real people.

189. Shawn - March 3, 2007

Just for nostalgia:

10 i=1
20 IF i 0 THEN
100 PRINT i;
110 ENDIF
120 PRINT
130 i = i + 1
140 GOTO 20
150 ENDIF
160 END

190. Shawn - March 3, 2007

It didn’t automatically filter the text, so I’ll try one more time with escape characters:

10 i=1
20 IF i < 101 THEN
30 IF i MOD 3 < 1 THEN
40 PRINT “Fizz”;
50 ENDIF
60 IF i MOD 5 < 1 THEN
70 PRINT “Buzz”;
80 ENDIF
90 IF i MOD 15 > 0 THEN
100 PRINT i;
110 ENDIF
120 PRINT
130 i = i + 1
140 GOTO 20
150 ENDIF
160 END

191. Shawn - March 3, 2007

Also, for fun:

Interviewee: I know how to programm in FB, do mind if I use that?
Interviewer: Go ahead.

start=1
end=100
fizz=3
buzz=5

192. Sam - March 3, 2007

Forth is under represented. So I’m going to post another Forth example that is even smaller than the first posting.

: eitherFizzBuzz dup 15 mod 0= if .” fizzbuzz” rdrop then ;
: orFizz dup 3 mod 0= if .” fizz” rdrop then ;
: orBuzz dup 5 mod 0= if .” buzz” rdrop then ;
: orNot dup . ;
: result eitherFizzBuzz orFizz orBuzz orNot ;
: fizzbuzz 1 begin dup 16 < while dup result cr 1+ repeat drop ;

193. Sam - March 3, 2007

let’s try coping the right version into the box this time. :(

: fizzbuzz 1 begin dup 101 %lt; while dup result cr 1+ repeat drop ;

194. pef - March 4, 2007

XSLT2:

195. pef - March 4, 2007

<xsl:for-each select=”1 to 100″>
<br/><xsl:value-of select=”if (not(. mod 15)) then ‘FizzBuzz’ else if (not(. mod 5)) then ‘Buzz’ else if (not(. mod 3)) then ‘Fizz’ else .”/>
</xsl:for-each>

196. OJ’s rants » Blog Archive » Why Can’t Programmers Program? - March 4, 2007

[...] come from, and how they get here, it’s no wonder that I have such an opinion. Have a read of this article to see the kinds of problems that computer science students are unable to solve. From the [...]

197. Ken - March 4, 2007

I was able to golf the ruby down by 3 characters :)

1.upto(?d){|i|p"#{[i%3<1?:Fizz:n='',i%5<1?:Buzz:n&&=i]}"}

198. Ken - March 4, 2007

Oops that’s 6 characters shorter using p, which is cheating a bit (quotes in output and all that). It’s 3 shorter if I had pasted the right one, using puts.

199. JJ - March 4, 2007

The reason why people can’t even program is, they are not even given a chance. You finish school and no one wants to hire you. 2 years pass and then employers expect you to program, when was the last time you did that?

I think people should be hired because they have merit, ambition, hard workers, eager to learn etc… Because you can hire computer geeks, only to find that their troubles worth more than their programming skills and how long will you put up with the troubles?

200. Jase! - March 4, 2007

C++

#include
int main(int argc, char** argv)
{
for(i = 1; i

201. Jase! - March 4, 2007

#include
int main(int argc, char** argv)
{
for(i = 1; i

202. Jase! - March 4, 2007

#include
int main( int argc, char** argv)
{
for(i=1; i

203. FizzBuzz, Enterprise Edition « Quoted For Truth - March 4, 2007

[...] Those of you who have been keeping up with the programming blogosphere have probably heard of FizzBuzz by now. Well, in the spirit of this, I decided to create my own overly complicated FizzBuzz: [...]

204. Enigma - March 5, 2007

Here is a compilable COBOL version. The COMPUTE verb was strictly avoided for full verbosity, so used the DIVIDE verb instead. Also, it uses Level 88s instead of EVALUATE. Adds some code to display the number in C-style format for the golf server contest.

http://www.fileden.com/files/2007/3/4/851496/fizzbuzz-contest-2.cob

Compiles on the OpenCOBOL.org compiler.

205. Will’s Blog - FizzBuzz and Problem Finding - March 5, 2007

[...] I followed a series of links to get to Jeff Atwood’s post on Why Can’t Programmers.. Program?  Jeff references, in turn, a post by Imran on Using FizzBuzz to Find Developers who Grok Coding. [...]

206. The Chances Are Nil » FizzBusted - March 5, 2007

[...] there has been a lot of buzz about FizzBuzz but Giles Bowkett in  his post FizzBuzters hit the nail right on the head: Keep in mind, FizzBuzz [...]

207. kyu - March 5, 2007

@ Jacob I can do it without using a 3rd variable and in only 3 lines (your *How fast they do it* issue)

X=2, Y=5

x=x+y \* x=7 *\
y=x-y \* y=2 *\
x=x-y \* x=5 *\

x=5, y=2 (Hence done…)

But you would just turn me down if i presented you with this solution.

how the hell is the interviewee supposed you want him to use a 3rd variable if he knows a better way of doing it? He is supposed to read your mind?

Anyway, sorry for the disturbamce.

208. geebutbut - March 6, 2007

#include
int main()
{
printf(”%d\n”, 1);
printf(”%d\n”, 2);
printf(”Fizz\n”);
printf(”%d\n”, 4);
printf(”Buzz\n”);
printf(”Fizz\n”);
printf(”%d\n”, 7);
printf(”%d\n”, 8);
printf(”Fizz\n”);
printf(”Buzz\n”);
printf(”%d\n”, 11);
printf(”Fizz\n”);
printf(”%d\n”, 13);
printf(”%d\n”, 14);
printf(”FizzBuzz\n”);
printf(”%d\n”, 16);
printf(”%d\n”, 17);
printf(”Fizz\n”);
printf(”%d\n”, 19);
printf(”Buzz\n”);
printf(”Fizz\n”);
printf(”%d\n”, 22);
printf(”%d\n”, 23);
printf(”Fizz\n”);
printf(”Buzz\n”);
printf(”%d\n”, 26);
printf(”Fizz\n”);
printf(”%d\n”, 28);
printf(”%d\n”, 29);
printf(”FizzBuzz\n”);
printf(”%d\n”, 31);
printf(”%d\n”, 32);
printf(”Fizz\n”);
printf(”%d\n”, 34);
printf(”Buzz\n”);
printf(”Fizz\n”);
printf(”%d\n”, 37);
printf(”%d\n”, 38);
printf(”Fizz\n”);
printf(”Buzz\n”);
printf(”%d\n”, 41);
printf(”Fizz\n”);
printf(”%d\n”, 43);
printf(”%d\n”, 44);
printf(”FizzBuzz\n”);
printf(”%d\n”, 46);
printf(”%d\n”, 47);
printf(”Fizz\n”);
printf(”%d\n”, 49);
printf(”Buzz\n”);
printf(”Fizz\n”);
printf(”%d\n”, 52);
printf(”%d\n”, 53);
printf(”Fizz\n”);
printf(”Buzz\n”);
printf(”%d\n”, 56);
printf(”Fizz\n”);
printf(”%d\n”, 58);
printf(”%d\n”, 59);
printf(”FizzBuzz\n”);
printf(”%d\n”, 61);
printf(”%d\n”, 62);
printf(”Fizz\n”);
printf(”%d\n”, 64);
printf(”Buzz\n”);
printf(”Fizz\n”);
printf(”%d\n”, 67);
printf(”%d\n”, 68);
printf(”Fizz\n”);
printf(”Buzz\n”);
printf(”%d\n”, 71);
printf(”Fizz\n”);
printf(”%d\n”, 73);
printf(”%d\n”, 74);
printf(”FizzBuzz\n”);
printf(”%d\n”, 76);
printf(”%d\n”, 77);
printf(”Fizz\n”);
printf(”%d\n”, 79);
printf(”Buzz\n”);
printf(”Fizz\n”);
printf(”%d\n”, 82);
printf(”%d\n”, 83);
printf(”Fizz\n”);
printf(”Buzz\n”);
printf(”%d\n”, 86);
printf(”Fizz\n”);
printf(”%d\n”, 88);
printf(”%d\n”, 89);
printf(”FizzBuzz\n”);
printf(”%d\n”, 91);
printf(”%d\n”, 92);
printf(”Fizz\n”);
printf(”%d\n”, 94);
printf(”Buzz\n”);
printf(”Fizz\n”);
printf(”%d\n”, 97);
printf(”%d\n”, 98);
printf(”Fizz\n”);
printf(”Buzz\n”);
return 0;
}

209. Devon Sean McCullough - March 6, 2007

; Common Lisp & Emacs Lisp both:

(do ((i 1 (1+ i)))
((> i 100))
(print
(if (zerop (mod i 5))
(if (zerop (mod i 3)) ‘FizzBuzz ‘Buzz)
(if (zerop (mod i 3)) ‘Fizz i))))

; Common Lisp only:
(loop for i from 1 to 100 do (format t “~[~[FizzBuzz~:;Buzz~]~:;~[Fizz~:;~D~]~]~&” (mod i 5) (mod i 3) i))

; Emacs Lisp only:
(do ((i 1 (1+ i)))
((> i 100))
(princ (format (aref ["%d\n" "Fizz\n" "Buzz\n" "FizzBuzz\n"]
(+ (if (zerop (mod i 3)) 1 0)
(if (zerop (mod i 5)) 2 0)))
i)))

; TECO … ha ha, that way lies madness!

210. Devon Sean McCullough - March 6, 2007

; Common Lisp & Emacs Lisp both:

(do ((i 1 (1+ i)))
((> i 100))
(print
(if (zerop (mod i 5))
(if (zerop (mod i 3)) ‘FizzBuzz ‘Buzz)
(if (zerop (mod i 3)) ‘Fizz i))))

; Common Lisp only:
(loop for i from 1 to 100 do (format t “~[~[FizzBuzz~:;Buzz~]~:;~[Fizz~:;~D~]~]~&” (mod i 5) (mod i 3) i))

; Emacs Lisp only:
(do ((i 1 (1+ i)))
((> i 100))
(princ (format (aref ["%d\n" "Fizz\n" "Buzz\n" "FizzBuzz\n"]
(+ (if (zerop (mod i 3)) 1 0)
(if (zerop (mod i 5)) 2 0)))
i)))

; TECO … ha ha, that way lies madness!

211. Devon Sean McCullough - March 6, 2007

no indent
two indents

212. Devon Sean McCullough - March 6, 2007

no indent
  two &nbsp;

213. Devon Sean McCullough - March 6, 2007

no indent
  one &nbsp; and one space

214. Devon Sean McCullough - March 6, 2007

 ; Common Lisp & Emacs Lisp both:
 
 (do ((i 1 (1+ i)))
  ((> i 100))
  (print
  (if (zerop (mod i 5))
  (if (zerop (mod i 3)) ‘FizzBuzz ‘Buzz)
  (if (zerop (mod i 3)) ‘Fizz i))))
 
 ; Common Lisp only:
 (loop for i from 1 to 100 do (format t “~[~[FizzBuzz~:;Buzz~]~:;~[Fizz~:;~D~]~]~&” (mod i 5) (mod i 3) i))
 
 ; Emacs Lisp only:
 (do ((i 1 (1+ i)))
  ((> i 100))
  (princ (format (aref ["%d\n" "Fizz\n" "Buzz\n" "FizzBuzz\n"]
  (+ (if (zerop (mod i 3)) 1 0)
  (if (zerop (mod i 5)) 2 0)))
  i)))
 
 ; TECO … ha ha, that way lies madness!

215. Devon Sean McCullough - March 6, 2007

; Common Lisp & Emacs Lisp both:

(do ((i 1 (1+ i)))
    ((> i 100))
  (print
   (if (zerop (mod i 5))
       (if (zerop (mod i 3)) ‘FizzBuzz ‘Buzz)
     (if (zerop (mod i 3)) ‘Fizz i))))

; Common Lisp only:
(loop for i from 1 to 100 do (format t “~[~[FizzBuzz~:;Buzz~]~:;~[Fizz~:;~D~]~]~&” (mod i 5) (mod i 3) i))

; Emacs Lisp only:
(do ((i 1 (1+ i)))
    ((> i 100))
  (princ (format (aref ["%d\n" "Fizz\n" "Buzz\n" "FizzBuzz\n"]
                       (+ (if (zerop (mod i 3)) 1 0)
                          (if (zerop (mod i 5)) 2 0)))
                 i)))

; TECO … ha ha, that way lies madness!

216. Devon Sean McCullough - March 6, 2007

What will it take to convince them to respect fixed-width &LT

217. Devon Sean McCullough - March 6, 2007

What will it take to convince them to respect fixed-width <PRE>formatted text?
If TCP were specified the way XML is, we’d still be using Kermit.

218. Devon Sean McCullough - March 6, 2007

Sure would be nice to have a preview or a way to flush the initial losing attempts, like everyone else has. How hard can it be to render indentation? Even in a variable width context it is mighty easy to keep track of a line’s worth of overhanging character widths and line ‘em up. Let ‘em define, say, &isp; seeing as how &nbsp; does the wrong thing already and <PRE> gets hosed by every blog and mail agent… rendered, as in a glue factory, the stench ruins property values many miles downwind.

Huh, that was fun. Hiring is costlier and harder than firing but I’m not sure stupid programming tricks are much help, how well they learn matters more than what they know.

219. Steven Woods - March 6, 2007

ASP Solution:

“)
Else
If I Mod 3 = 0 Then
Response.Write(”Fizz “)
Else
If I Mod 5 = 0 Then
Response.Write(”Buzz “)
Else
Response.Write(i & ” “)
End If
End If
End If
Next
%>

220. Steven Woods - March 6, 2007

bah, it killed my code:

Try again!

<%
For i = 1 To 100

If I Mod 3 = 0 And I Mod 5 = 0 Then
Response.Write(”FizzBuzz<br /> “)
Else
If I Mod 3 = 0 Then
Response.Write(”Fizz<br /> “)
Else
If I Mod 5 = 0 Then
Response.Write(”Buzz<br /> “)
Else
Response.Write(i & “<br /> “)
End If
End If
End If
Next
%>

221. Hans Bezemer - March 6, 2007

Tiny, may be hard to comprehend, but a touch of originality?? This is done with 4tH (a forth dialect):

: zap dup 0 .r ; : fizz .” Fizz” ; : buzz .” Buzz” ; : fizzbuzz fizz buzz ;
create foo ‘ zap , ‘ fizz , ‘ buzz , ‘ fizzbuzz ,
:this foo does> >r dup 3 mod 0= 2* over 5 mod 0= + cells r> + @c execute drop ;
: bar 101 1 do i foo space loop ; bar

222. Oliodu - March 6, 2007

['FizzBuzz' if (i%15==0) else ('Fizz' if (i%3==0) else ('Buzz' if (i%5==5) else i)) for i in range(1,101)]

223. Oliodu - March 6, 2007

Sorry, a typo in previous post. Here is the right one. (Python, if you have to ask)

print ['FizzBuzz' if (i%15==0) else ('Fizz' if (i%3==0) else ('Buzz' if (i%5==0) else i)) for i in range(1,101)]

Why do any one need to do this in multiple lines?

224. stevec - March 6, 2007

I noticed almost all the fizzbuzz solutions use mod instead of addition or subtraction. I guess code size, not clock cycles is the priority for most.

225. zepto - March 7, 2007

I’ve noticed this too, and from an efficiency standpoint, doing 100+ division or modulo operations would really be frowned upon. maybe it should be changed to solve fizzbuzz without modulo.

226. zepto - March 7, 2007

looking further, we can see a pattern between
positive natural multiples of 1 (n)
multiples of 3 (t)
and multiples of five (f)
1+2(1) = 3+2(1)= 5
2+2(2) = 6+2(2)= 10
3+2(3) = 9+2(3)= 15
n = 1,2…etc
t = n + 2(n)
f = t + 2(n)
maybe someone can come up with a super elegant solution using that

227. Wayne - March 7, 2007

Fools

228. FizzBuzz « danseagrave - March 7, 2007

[...] Just a quick pointer over to more discussion of the FizzBuzz [...]

229. Michael Pohoreski - March 7, 2007

Divisions are slow, especially on embedded devices.

int i3 = 2;
int i5 = 4;

const int N = 100;
for( int i = 1; i

230. Michael Pohoreski - March 7, 2007

int i3 = 2;
int i5 = 4;

const int N = 100;
for( int i = 1; i < N; i++ )
{
if ((i3 == 0) || (i5 == 0))
{
if (i3 == 0)
{
printf( “fizz” );
i3 = 3;
}
if (i5 == 0)
{
printf( “buzz” );
i5 = 5;
}
printf( “\n” );
}
else
{
printf( “%d “, i );
}
i3–;
i5–;
}

231. Michael Pohoreski - March 7, 2007

int OUTPUT_BASE = 10;
char * Print( const int n )
{
int x = n;
bool bNegative = false;
if (x < 0)
{
bNegative = true;
x = -x; // abs|x|
}

// 2^32 = 10 digits
// 1 char for null term, 1 char for, total min = 12 chars
const int MAX_DIGITS = 16;
static char sBuf[ MAX_DIGITS ];

char *pText = sBuf + MAX_DIGITS;
*–pText = 0;

while (x >= 0)
{
int nDigit = (x % OUTPUT_BASE);
*–pText = (’0′ + nDigit);
x -= nDigit;
x /= OUTPUT_BASE;

if (x == 0)
{
break;
}
}

if (bNegative)
{
*–pText = ‘-’;
}

return pText;
}

232. Michael Pohoreski - March 7, 2007

Guess the double minus sign got munched when converted to html.
i.e.
* – – pText = 0;

233. Ed Courtenay - March 7, 2007

Equally, a completely over-engineered solution can be just as bad! Take this C# version as an example:

using System;

namespace FizzBuzz
{
internal class Program
{
private static void Main()
{
IFormatProvider formatProvider = new FizzBuzzFormatter();

for (int i = 1; i

234. Ed Courtenay - March 7, 2007

Attempt #2

using System;

namespace FizzBuzz
{
internal class Program
{
private static void Main()
{
IFormatProvider formatProvider = new FizzBuzzFormatter();

for (int i = 1; i < = 100; i++)
Console.WriteLine(String.Format(formatProvider, “{0:FB}”, i));

Console.ReadLine();
}
}

internal class FizzBuzzFormatter : ICustomFormatter, IFormatProvider
{
public string Format(string format, object arg, IFormatProvider formatProvider)
{
if (format == null)
return String.Format(”{0}”, arg);

if (format.StartsWith(”FB”) && arg is int)
{
int val = (int) arg;
bool mod3 = val%3 == 0;
bool mod5 = val%5 == 0;

if (!mod3 && !mod5)
return arg.ToString();

string s = String.Empty;

if (mod3)
s += “Fizz”;

if (mod5)
s += “Buzz”;

return s;
}

return String.Format(”{0:” + format + “}”, arg);
}

public object GetFormat(Type formatType)
{
if (formatType == typeof (ICustomFormatter))
return this;
else
return null;
}
}
}

235. Richard - March 7, 2007

Jacob wrote (weighing in at Number 3):

Ask: show me (on paper, but better on a whiteboard) how you would swap the values of two variables.

If they don’t *start* with creating a third variable, you can pretty much write that person off. I’ve found that I can cut a third to half my (admittedly at that point unscreened) applicants with that question alone.

OT but one other way if they are numbers, (similary to XOR trick):
b = a + b
a = b – a
b = b – a

236. Nigel Ainscoe - March 7, 2007

Not seen a FoxPro example so:

for ln = 1 to 100
do case
case mod(ln,5) = 0 and mod(ln/3) = 0
? ‘FizzBuzz’

case mod(ln,5) = 0
? ‘Buzz’

case mod(ln/3) = 0
? ‘Fizz’

otherwise
? ln
endcase
next ln

237. Nigel Ainscoe - March 7, 2007

It stole my formatting!!

238. stevec - March 8, 2007

There are some pretty clever programmers here who have left me with some questions. Those using XOR, are you XORing the value or a pointer to the value? For those using addition/subtraction to swap, I’ll assume you only intend this for numeric values and that you probably also assumed the type would not change over the lifespan of the program (interview). But what happens if the summation overflows? Is it numerically stable for floating point values?

239. larsx2 - March 10, 2007

I just wanted to put something :P , sorry if u think that my code is not good..

# on Ruby

x = 0
while x

240. larsx2 - March 10, 2007

I just wanted to put something :P , sorry if u think that my code is not good..
XD
# on Ruby

x = 0
while x

241. Blog by Aji Issac Mathew aka AjiNIMC » Hmm… - 199 out of 200 programmers can’t program - March 10, 2007

[...] Using FizzBuzz to Find Developers who Grok Coding – [...]

242. Mondo - March 10, 2007

This thread is a parody. A quick scan of the suggested answers reveals almost no correct responses. Did you people even read the question?

243. Chasing Mugiwara » Blog Archive » Fizz Buzz - March 11, 2007

[...] was a discussion some time ago about the lack of quality programmers applying for jobs and that even asking applicants to create basic code could sadly filter out most [...]

244. The FizzBuzz Test For Developers « Rhonda Tipton’s WebLog - March 11, 2007

[...] Topics-]Using FizzBuzz to Find DevelopersWhy Can’t Programmers.. Program?Measuring Programmer Competence via FizzBuzz [...]

245. FizzBuzz.rb - March 12, 2007

[...] my FizzBuzz solution: [...]

246. Jonas Gorauskas - March 12, 2007

In C#:

public static void Main()
{
  Console.WriteLine("FIZZBUZZ:\n");
  for (int i = 1; i
    if ((i%3==0) && (i%5==0)) {
      WL("FizzBuzz");
    } else if (i%3==0) {
      WL("Fizz");
    } else if (i%5==0) {
      WL("Buzz");
    } else {
      WL(i.ToString());
    }
  }
  Console.ReadLine();
}

247. smog - March 12, 2007

ruby (58):
1.upto(?d){|i|puts”FizzBuzz”[4&a=i*i%3*5,9-a-i**4%5]||i}

python (60):
for i in range(1,101):print”FizzBuzz”[i*i%3*4:8--i**4%5]or i

248. smog - March 12, 2007

Oops, I left out a crucial – sign in the python one:

for i in range(1,101):print”FizzBuzz”[i*i%3*4:8–-i**4%5]or i

-i**4%5 always returns 4 if i is not a multiple of 5 (0 elsewise)
(If you leave out the – it returns 1)

249. Hexten » Blog Archive » FizzBuzz in 6502 assembler - March 12, 2007

[...] FizzBuzz is an extremely basic competence test for programmers. So I thought I’d write a version extremely in BASIC. Here it is in BBC Basic’s embedded 6502 assembler. For added geek points I used a 6502 emulator written in Perl to develop it on. [...]

250. Andy Armstrong - March 12, 2007

Here it is in BBC Basic’s embedded 6502 assembler. For added geek points I used a 6502 emulator written in Perl to develop it on.

10 REM FizzBuzz in 6502 assembler
20 DIM code% 1000
30 OSWRCH = &FFEE
40 OSNEWL = &FFE7
50 work = &70
60 DIM FizzM 4 : $FizzM = “zziF”
70 DIM BuzzM 4 : $BuzzM = “zzuB”
80 FOR pass% = 0 TO 3 STEP 3
90 P%=code%
100 [opt pass%
110
120 .FizzBuzz LDA #1
130 LDX #3
140 LDY #5
150 .FB1 SEC
160 DEX
170 BNE FB2
180 JSR Fizz
190 LDX #3
200 .FB2 DEY
210 BNE FB3
220 JSR Buzz
230 LDY #5
240 .FB3 BCC FB4
250 JSR PrDecimal
260 .FB4 PHA
270 JSR OSNEWL
280 PLA
290 CLC
300 ADC #1
310 CMP #101
320 BCC FB1
330 RTS
340
350 .Fizz PHA
360 LDX #3
370 .Fizz1 LDA FizzM, X
380 JSR OSWRCH
390 DEX
400 BPL Fizz1
410 CLC
420 PLA
430 RTS
440
450 .Buzz PHA
460 LDY #3
470 .Buzz1 LDA BuzzM, Y
480 JSR OSWRCH
490 DEY
500 BPL Buzz1
510 CLC
520 PLA
530 RTS
540
550 .PrDecimal STA work
560 PHA
570 TXA
580 PHA
590 LDA #0
600 PHA
610 .PrDec0 LDX #8
620 LDA #0
630 .PrDec1 ASL work
640 ROL A
650 CMP #10
660 BCC PrDec2
670 SBC #10
680 INC work
690 .PrDec2 DEX
700 BNE PrDec1
710 CLC
720 ADC #ASC"0"
730 PHA
740 LDX work
750 BNE PrDec0
760 .PrDec3 PLA
770 BEQ PrDec4
780 JSR OSWRCH
790 JMP PrDec3
800 .PrDec4 PLA
810 TAX
820 PLA
830 RTS
840 ]
850 NEXT

251. Shawn - March 13, 2007

In the Brainfuck language:

>+++++++++[-][-]>[-]+>+>[>-]>>>
[-]>>++>[-][-]>[>>+[-]>>+>[>>-]>[-]++>->+>+>>[>>-]>[-][-]>+[-]>-]>>>[>+>+>[>-]>>>>-
]>[-]>[-]++++[-]++++[-]+
++++[-]>[>>+>+
>>[>>-]>>>-]++++[-]+++++++++[-]+++++++[-]++++++[-]++++++
++[-]+++++++++[-]++++++++
[-]++++++++[-]+++++++[-]++++++++[-]++[-]+++++++++[-]>>[>+>+>[>-]>>>>-]>>+++
+[-]++++[-]+++++[-]>[>>+>+>>[>>-]>>>-]++++[-]+++++++++[-]+++++++[-]++++++[-]++++++++++[-]+++++++[-]+++++++[-]++++++++[-]+++++++[-]+++++++[-
]++++++++[-]
+++++[-]++++
+++[-]++++++++[-]+++[
-]+++[-]+++++++++[-]+++++++[-]++++++++[-]+++++[-]+++[-]++++++++[-][-]>[
-]+>+>[>-]>>>[-]>>++>[-][-]>[>>+[-]>>+>[>>-]>[-]++>->+>+>>[>>-]>[-][-]>+[-]>-]>>>[>+>+
>[>-]>>>>-]>[-]>[-]++++[
-]++++[-]+++++[-]>[>>+>+>>[>>-]>>>-]++++[-]+++++++++[-]+++++++[-]++++++[-]
++++++++[-]+++++++++[
-]++++++++[-]++++++++[-]+++++++[-]++++++++[-]++[-]+++++++++[-]

252. Jason - March 13, 2007

Shorter Common Lisp version:
(dotimes(i 100)(format t”~A ~[Fizz~:;~]~[Buzz~:;~]~%”i(mod i 3)(mod i 5)))

74 bytes!

253. intangible - March 14, 2007

Perl:

while($i++

254. intangible - March 14, 2007

Perl again:

while($i++<100){print$i%3&&$i%5?$i:$i%3?Buzz:$i%5?Fizz:FizzBuzz,”\n”}

255. John - March 14, 2007

Another Forth solution. Not as nicely factored as the earlier one.

: .fizzbuzz ( n )
space dup 3 mod 0= over 5 mod 0= 2dup or >r
swap if .” fizz” then if .” buzz” then
r> if drop exit then . ;
: numbers 101 1 do i .fizzbuzz loop ;

256. willc2_45220 - March 15, 2007

Here’s an Applescript (8 minutes)

– fizz buzz

set holder to {}

repeat with i from 1 to 100

set flag to (i as string)

if (i / 3) = ((i / 3) as integer) then

set flag to “Fizz”

end if

if (i / 5) = ((i / 5) as integer) then

if flag = “Fizz” then
set flag to “FizzBuzz”

else
set flag to “Buzz”
end if

end if

set end of holder to flag

end repeat

holder

257. willc2_45220 - March 15, 2007

doh, tabs got stripped and the first line is a comment (DASH, DASH)

258. kurapikats - March 15, 2007

correct php code:

for ($i = 1; $i “;
} elseif ($i % 3 == 0) {
echo “fizz” . “”;
} elseif ($i % 5 == 0) {
echo “buzz” . “”;
} else {
echo $i . “”;
}
}

259. kurapikats - March 15, 2007

for ($i = 1; $i “;
} elseif ($i % 3 == 0) {
echo “fizz” . “”;
} elseif ($i % 5 == 0) {
echo “buzz” . “”;
} else {
echo $i . “”;
}
}

260. kurapikats - March 15, 2007

correct php code

for ($i = 1; $i “;
} elseif ($i % 3 == 0) {
echo “fizz” . “”;
} elseif ($i % 5 == 0) {
echo “buzz” . “”;
} else {
echo $i . “”;
}
}

261. Craig - March 15, 2007

You people writing the swap function are missing the point… I don’t think the interviewer is telling you that you’re given an integer. Rather, you need to write code that can swap two of the same type, no matter what that type is.

You would only use XOR or addition/subtraction if you’re given some integer type. Otherwise, you’d probably make use of some temp variable of the same type as those objects you are swapping.

262. Mat - March 15, 2007

Why are people posting code comments?
Get a job!

263. Subash - March 17, 2007

Apart from giving _FizzBuzz_ sort of programs, I got to interview candidates for a Senior Programmer position last month, and part of the game was to guide juniors in contacting the Database.

We got a lot of guys who had 3+ years of experience, many websites in their resumes quantifying their skills, and most of them had a good time with MySQL.

After initial screening we got three guys to the final rounds. They seemed perfect on pgming and db concepts, whizzed thru normalization concepts, different types of joins, …

But I know I’m quite sneaky. When I asked them to write an SQL query to get data from these two tables using a JOIN, my fellow interviewers sneered at my question. After intent thinking, this was what the star candidate wrote:

select * table1 inner join table2 where t1.id = t2.city

We’re still searching for a Senior programmer…

264. ore-kelate-biasa-biasa - March 19, 2007

alias otak_fizzbuz {
var %x = 1
while (%x

265. craig wilcox - March 19, 2007

What would you think of a candidate who wrote a main loop that looked something like this?:

static void Main(string[] args) {

IFizzBuzzEmitter emitter;

for(int i = 1; i

266. Alex - March 20, 2007

If I need to hire someone, I think I’ll post a trivial programming challenge on a blog, and weed out any so-called engineers incapable of taking the ten seconds needed to notice the dozens of people before them whose code was ruined by unescaped less-than signs.

As a bonus test, I’ll post an early comment under an alias in which I claim to weed out people using an even simpler test. The catch is that my expected solution is actually less than optimal, and I am potentially weeding out those smarter than myself. Those who – thinking themselves smarter – post solutions which have already been posted more than once can be safely weeded out.

I’d also like to give a special shout-out to those golfers who forget to test before posting. Golfer, meet my friend Mr. Irb.

267. Nick - March 20, 2007

“Why do people always insist on writing one-liners?”

There are other priorites in the commercial software world than mere code size, and a candidate that starts making assumptions about what those are is displaying a flaw that allows you to discount them.

Working on team software I prefer coders who remember Brian Kernighans maxim:

“Debugging someone else’s code is twice as hard as writing the code yourself.” –Brian Kernighan

268. Studiowhiz.com » Blog Archive » Unit Tests for Fizzbuzz?! - March 20, 2007

[...] anyone who has been following the FizzBuzz – saga, someone has now written a full Java implementation complete with Unit [...]

269. Buu Nguyen’s Blog » Imran on interviewing programmers - March 21, 2007

[...] this to see how Imran tests his interviewees.  Being curious if the test had some tricks which [...]

270. Loosely Typed in Ohio. » FizzBuzz…The SQL Version - March 21, 2007

[...] tech blogosphere was humming last week about FizzBuzz, a simple test to figure out if your candidate can write even a trivial program. Write a program [...]

271. Maan’s Blog » Archives » FizzBuzz - March 22, 2007

[...] is a quick code I wrote to try myself with an interview coding question from this article. Basically it took me 10 min to write the whole thing (I tried to write it as neat and as elegant [...]

272. AndreasB - March 22, 2007

perl while($i++

273. ka - March 22, 2007

I’m 4 and I did this

what a bunch of idiots

penis size = 111 in.

274. ka - March 22, 2007

the kicker about all this is that you’re using an online ‘out of the box’ blogging site to ‘bitch’ about people that can’t program…

Like a fucking blog would be that hard to write yourself :P

you don’t even have your own install of WP, you’re using THEIR service…

l4m3

——————————————
on a more respectful note:

I’m the Lead Developer (don’t consider myself a programmer) with 7 years of experience with so many awards under my belt it would crash your *insert output environment here* if you tried to loop through them.

I could easily do this, however as a web developer looking to hire someone, I would be much more worried about ‘other’ things then things I can essentially teach them.

* how well do they communicate?
* what do they understand about the business side of their particular field? things such as ROI (Clients don’t want to hear b/s about programming, they want to know how it makes them money or how they can get a return on their technology investment)
* are they quick learners?
* are they overall balanced with other tasks? (it would suck to hire someone who is so smart they can program fizzbuzz but can’t do anything else).
* will they get along with everyone else they need to work with

Those (imo) are much more pressing things to evaluate in an interview then some task of measuring ones penis size.

Ask some basic programming questions.

* What can you tell me about OOP?
* What is the ‘proper’ way to insert data into a database?

etc etc etc.

Would be much more profitable in finding a ‘good programmer’ who might also be a great person to work with.

275. mv - March 24, 2007

My own experience working with new hires fresh from school is that they very often can do the algorithmic stuff but fall down on the things that make ‘real world’ programming different from school: changing requirements, change control, evaluating multiple designs and communicating their thought processes clearly.

And follow-through: in the academic environment, 90% gets a ‘A’, you work alone, and you almost never revisit the issue. Would that it were that way in the commercial environment!

276. Jon - March 26, 2007

To all those self-proclaimed experts who think you shouldn’t hire people who don’t XOR to swap variables, I’d suggest that a) you devalue the importance of optimisation as a hiring criteria, and b) you read the comp.lang.c. faq a few more times: http://c-faq.com/expr/xorswapexpr.html

277. beton - March 28, 2007

beat me, please B)

278. find » Using FizzBuzz to Find Developers who Grok Coding - April 1, 2007

[...] Original post by tickletux [...]

279. Royal Miah - April 3, 2007

ben we are talking about memory level swaping not high level.

280. forward - April 4, 2007

Want to know why this subject is so popular?

Because it makes everyone who thinks they are a programmer feel good, and gives them a sense of worth (because if you read stuff like this, you most likely can do the test).

I think most people who are computer programmers were kind of social misfits originally (and probably still are (I am including myself)). So nothing like a simple test to give a programmer a sense of self worth.

Same principle applies to those TV shows that ask people on the street a stupid question that they get wrong. Everyone at home gets to sit there and say, “Man, that guy is stupid, and man, am I smart!”.

Yeah, yeah…. we are all smart. Now get back to work :) .

(wanna a real test? program something that when compiled, produces a Ferarri :) …. im still working on that one….

281. World of Ruby Indonesia fizzbuzz, dibuang sayang « - April 5, 2007

[...] bisa nggak? h eh eh 5:28:11 PM dewa_error1: search fizzbuzz di google :-) 5:28:37 PM dewa_error1: http://tickletux.wordpress.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/ 5:29:30 PM dewa_error1: “Want to know something scary ? – the majority of comp sci graduates [...]

282. kost BebiX - April 5, 2007

Jacob, about your problem about swapping variables values.
I know the method with

a = a + b;
b = a – b;
a = a – b;

but it works slower then just

c = a; a = b; b = c;

So it’s better to use second one.

283. Syam Kumar R. - April 6, 2007

<?php
for($i =1; $i < 101; $i++)
{
if($i % 3 == 0) print “Fizz”;
if($i % 5 == 0) print “Buzz”;
if($i % 3 != 0 && $i % 5 != 0) print $i;
print “<br />”;
}
?>

284. PsyckBoy - April 10, 2007

I’m still working on the solution in INTERCAL. I’ll be done any day now.

285. Army1987 - April 15, 2007

What the hell?

#include
#define MAX 100
#define FIZZ 3
#define BUZZ 5

void fizzbuzz(int n)
{
if (n%FIZZ == 0)
printf(”Fizz”);
if (n%BUZZ == 0)
printf(”Buzz”);
if (n%FIZZ && n%BUZZ)
printf(”%d”, n);
}

int main(void)
{
int i;
for (i=1; i

286. phr - April 15, 2007

My preferred (extensible) python fizzbuzz:

fizzbuzz = ((3, ‘Fizz’), (5, ‘Buzz’))
def fizzify(n):
fb = ”.join(b for a,b in fizzbuzz if n%a == 0)
return fb or str(n)

for i in xrange(1,100): print fizzify(i)

I hope I didn’t mess this up ;-)

287. phr - April 15, 2007

Heh, I did mess it up (aside from the comment function clobbering python indentation). That should have said xrange(1,101) in order to print the numbers up to and including 100.

288. Greg - April 16, 2007

I read about half the comments and gave up. All these guys who say “this is too hard/unrealistic/stressful in an interview”.

YOU are the kind of programmer that people are talking about here. I wrote the VB 6.0 implementation of this in 22 seconds.

The point is extremely valid. This test is so simple, if you can’t do it, you don’t deserve a programming job.

289. Bart - April 16, 2007

I worked at a small software consultancy company where we had a similar test. We had a laptop ready and asked the candidate to write some simple code – similar to the fizzbuzz test.

One thing we were looking for: the speed at which the code was typed.

“Experienced Programmer”, typing with two fingers and looking up every single key? I don’t think so…

290. bruno - April 16, 2007

Just to answer to comment #3 from Jacob: some languages are smart enough to let you swap 2 vars without a temporary one. The following works at least with Python and Ruby:

a, b = b, a

FWIW, I’d probably rule off someone claiming experience with one of these languages and using a temporary variable !-)

291. qebab - April 17, 2007

I’m self taught, and only know a bit of python. I don’t even know how to escape the lesser than operator in html! However, this is just a test of logical thinking, and it was easy.
Pseudo code would be f. ex.

for every number between 1 and 100 (100 included)
output = empty string
if number mod 3 is 0: output = output + Fizz
if number mod 5 is 0: output = output + Buzz
if output is an empty string: output = number
print output

I wrote a ‘golfed’ version but changed it to a function after some comments here, so let’s call i t a golfed function.
def fizzbuzz(limit,tests,words)
i=1
while limit>i:print words[0]*(i%tests[0]==0)+words[1]*(i%tests[1]==0)or i;i+=1

The golfed version was simply:
i=1
while 101>i:print’Fizz’*(i%3==0)+’Buzz’*(i%5==0)or i;i+=1

As aforementioned, I’ve got no idea how to escape lesser than in html, but if I did, I’d change the ==0 to lesser than 1.

I liked the test, and I agree that if you can’t do it, you’re probably not suited to program for a living.

292. Basilisk - April 18, 2007

Maybe it’s just how my mind really works, but here’s a backwards-thinking Python solution:

def fizzbuzz(n):
m3 = n % 3
m5 = n % 5
m_both = m3 or m5
if not m_both:
return “Fizz-Buzz”
elif not m5:
return “Buzz”
elif not m3:
return “Fizz”
else:
return n

for x in range(1, 101):
print fizzbuzz(x)

Silly, eh?

293. Fizz Buzz « My raves, my rants, a piece of me - April 19, 2007

[...] using-fizzbuzz-to-find-developers-who-grok-coding Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” [...]

294. Halop - April 20, 2007

Well, in our case the problem was not about programming skills. I wouldnt mention this if it was a single case, but it seems quite common. Not long ago we hired a ruby developer who i think actually was dreaming in code… I swear i have never met a better coder in my life. Whatever the problem was he could come up with the solution right away, then two minutes later he optimized the code to a hm. “one-liner”. But when it came to actual work, this guy could not finish a single job on time. We used to give him deadlines of several days less than the actual deadline just to be sure that it will be done. And even this didnt work sometimes, and of course it was always someone elses fault. Then add to this, that he changed the look and function of the projects when he felt neccessary (and he usually did :) , because the client is ofcourse stupid and doest know what he really wants. The code he produced at the end was always clean, efficient – perfect in a sense, but well, we got fed up with this everyone being stupid and he knowing everything better attitude, and the constant delays, and the constant “surprises”, and that we had to literaly force him to do what we are payed for and not what he likes better. My point is, that being a good coder is only one part of it, and – well, for me at least – being able to actually do a job is just as important. So if i have to choose between a coder who does FizzBuzz in 20 seconds and says everyone above 30secs is stupid and Fizzbuzz is a stupid game too and he could come up with a better one anytime, and one who does it in 2 minutes and then waits for the next question, well i would stick with the second one. ;)

295. ka - April 20, 2007

@Halop

This is exactly why companies have HR depts and programmers have no business hiring someone, only recommending them ;)

296. Anson - April 21, 2007

I’m surprised there haven’t been more Perl solutions.

foreach ((1..100)) {
$fizzbuzz = “”;
$_ % 3 eq 0 and $fizzbuzz = “Fizz”;
$_ % 5 eq 0 and $fizzbuzz .= “Buzz”;
$fizzbuzz and print “$fizzbuzz\n” or print “$_\n”;
}

297. Anson - April 21, 2007

And here’s one with no division done:

$f = $b = 0;
foreach ((1..100)) {
++$f eq 3 and print “Fizz” and $f = 0;
++$b eq 5 and print “Buzz” and $b = 0;
$f ne 0 and $b ne 0 and print “$_”;
print “\n”;
}

298. Jan - April 24, 2007

ummmm… if you’re looking for “Developers”, then this sort of question is rather pointless. Sure, it may winnow out some obviously unskilled candidates but you will also dismiss many talented people who can help you greatly.

There is a huge difference between a developer and a programmer. A developer’s overall job is much larger, and much more complex. The programmer’s individual tasks may be complex, and that’s where you need rigorous skills, but of far more use is the ability to design and implement and learn on the job.

I see this sort of thing as programmer silliness. It’s merely programmer elitism: if you can’t do x then you’re not as good as me. Very silly.

Each person in a team brings different skills. In some area that person will probably be _better_ than you. They may advance your business or project in ways that you didn’t even anticipate, but you won’t find out because you’ve abitrarily rejected them based on a very piddling test.

Instead of finding the ideal geek, I would try to find the person who can mix in well and who knows how to _learn_ what s/he needs to know.

299. Fried Chicken Arcade - April 28, 2007

[...] Using FizzBuzz to Find Developers who Grok Coding This simple test apparently can weed out those who cannot code. Try it for yourself! (tags: coding internet) [...]

300. simple singularities » FizzBuzz Problem - May 11, 2007
301. JavaSPEKTRUM Blogosphäre » Blog Archiv » Blogosphäre (aus JavaSPEKTRUM 03/07) - May 15, 2007

[...] zu häufig die Probleme schon bei den absoluten Grundlagen beginnen und schlägt einen trivialen Programmiertest namens FizzBuzz als erste Hürde für ein Gespräch vor. Die Aufgabe: Schreiben Sie ein Programm, das die Zahlen [...]

302. Solving the Fizz-Buzz Question | FuCoder.com - May 17, 2007

[...] quoted Irman’s FizzBuzz question, a trivial programming problem but surprisingly has stumbled many job applicants. Here is the [...]

303. abu ameerah - May 18, 2007

FizzBuzz is awesome!

304. abaqueiro - May 19, 2007
305. Best of Feeds - 29 links - blogging, seo, programming, search, google, humor « //engtech - internet duct tape - May 21, 2007

[...] Using FizzBuzz to Find Developers who Grok Coding (tickletux.wordpress.com, 4 saves) [...]

306. pixolut - May 22, 2007

At Pixolut we do a 6 hour practical exam with only a single UML diagram as the question. “Implement this”.

The exam requires unit tests be written for parts of the system that can be tested and the candidate should use an ‘inversion of control’ pattern to create mock objects to test the abstract functionality.

We allow any modern OO style language that has a test framework (pretty much any modern language today) and the programmer can bring in any materials they want and access the internet as much as they need.

This exam applies accross language barriers (spoken and programmed!) and successfully sorts out the fluff. The good thing though, is that it is practical and as such illustrates the shades of grey which defines an individual.

Example: I had someone take the exam and finish it in 3 hours instead of 6. Some code was a bit sloppy but the solution worked perfectly. This result showed me exactly where I would have to keep an eye out for issues and also where his strengths were.

Joe Cincotta: blog.pixolut.com

307. Dragon’s Notes » The FizzBuzz Test - May 26, 2007

[...] ran across this blog post the other day, while browsing around some programming sites after making an update to CharacterGen [...]

308. Alfred Kayser - May 31, 2007

One of the most optimal solutions in C:
#include
main() {
for(int i=1;i

309. Alfred Kayser - May 31, 2007

Another try:
#include <stdio.h>
main() {
for(int i=1;i%lt;=100;i++) {
printf(i%15?i%3?i%5?”%i\n”:”Buzz\n”:”Fizz\n”:”FizzBuzz\n”);
}
}

310. Alfred Kayser - May 31, 2007

Another try:
#include <stdio.h>
main() {
  for(int i=1;i<=100;i++) {
    printf(i%15?i%3?i%5?”%i\n”:”Buzz\n”:”Fizz\n”:”FizzBuzz\n”);
  }
}

So, the hard part is not coding it, but posting the code as a comment on a blog. ;-)

311. John - May 31, 2007

I think a lot of you are missing the point. its not about code elegance or refactoring, its about the simple duplicate line of code staring you in the face. How do I know? Well I answered it wrong too ;) . Its so easy its staring you right in the face:

for ( int i = 1 ; i

312. John - May 31, 2007

for ( int i = 1 ; i <= 100; i ++ ) {
if (i % 3 == 0 ) print “Fizz”;
if (i % 5 == 0 ) print “Buzz”;
else print i;
// formatting purposes
print “\n”;
}

313. Jason - May 31, 2007

HAI
CAN HAS STDIO?
I HAS A VAR

IM IN YR LOOP
UP VAR!!1
IS VAR OVAR 3 LIEK 0?
VISIBLE “FIZZ”
IS VAR OVAR 5 LIEK 0?
VISIBLE “BUZZ”
IS VAR OVAR 3 LIEK 0 AND VAR OVAR 5 LIEK 0?
VISIBLE “FIZZBUZZ”
IZ VAR BIGR THAN 100? GTFO. KTHX
IM OUTTA YR LOOP
KTHXBYE

314. Damian Brasher - June 1, 2007

#!/bin/bash
i=”1″
n=”0″
t=”0″
while [ $i -lt 101 ];
do
n=$[$i%3]
t=$[$i%5]
if ((”$t” == 0)) && ((”$n” == 0)); then
echo “FizzBuzz”
elif [ $n == 0 ]; then
echo “Fizz”
elif [ $t == 0 ]; then
echo “Buzz”
else
echo “$i”
fi
i=$[$i+1]
done
exit 0

315. Hugo Mills - June 1, 2007

I’m amazed that nobody’s done it in the paragon of languages…

/Test {
3 2 roll
exch mod 0 eq
{ show true }
{ pop false }
ifelse
} bind def

/mm { 25.4 div 72 mul } bind def

/Helvetica findfont
12 scalefont setfont
72 297 mm 72 sub translate

1 1 100 {
dup 1 sub dup 50 idiv 288 mul exch 50 mod 14 mul neg moveto
dup false exch
dup (Fizz ) 3 Test
exch (Buzz) 5 Test
or or not { 3 string cvs show true } if
pop
} for

showpage

316. PHoog - June 4, 2007

Console.WriteLine(”1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n16\n17\nFizz\n19\nBuzz\nFizz\n22\n23\nFizz\nBuzz\n26\nFizz\n28\n29\nFizzBuzz\n31\n32\nFizz\n34\nBuzz\nFizz\n37\n38\nFizz\nBuzz\n41\nFizz\n43\n44\nFizzBuzz\n46\n47\nFizz\n49\nBuzz\nFizz\n52\n53\nFizz\nBuzz\n56\nFizz\n58\n59\nFizzBuzz\n61\n62\nFizz\n64\nBuzz\nFizz\n67\n68\nFizz\nBuzz\n71\nFizz\n73\n74\nFizzBuzz\n76\n77\nFizz\n79\nBuzz\nFizz\n82\n83\nFizz\nBuzz\n86\nFizz\n88\n89\nFizzBuzz\n91\n92\nFizz\n94\nBuzz\nFizz\n97\n98\nFizz\nBuzz\n”);

317. Petal and Paws - June 4, 2007

How to Fizzbuzz…

Okie, so it’s simple enough… right?
Write a program that prints the numbers from 1 to 100. 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 …

318. Robspages - June 6, 2007

PHP

for($i=1; $i < 101; $i++){
switch(true){
case ($i % 3 == 0 && $i % 5 == 0):
echo “FizzBuzz <br/&grt;”;
break;
case ($i % 3 == 0):
echo “Fizz <br/&grt;”;
break;
case ($i % 5 == 0):
echo “Buzz <br/&grt;”;
break;
default:
echo $i . ” <br/&grt;”;
break;
}
}

319. Robspages - June 6, 2007

gah – botched the >

320. Alex Oren - June 6, 2007

C++ template metaprogramming.
Everything is calculated at compile time and the result is just a series of printf() calls.

////////////////////////////////////////////////////////////////

#include

#if defined(_MSC_VER) && _MSC_VER >= 1300
#define inline __forceinline
#endif

////////////////////////////////////////////////////////////////

template struct fb
{ static inline void Do() { printf(”%i\n”, I); } };

template struct fb
{ static inline void Do() { printf(”fizzbuzz\n”); } };

template struct fb
{ static inline void Do() { printf(”fizz\n”); } };

template struct fb
{ static inline void Do() { printf(”buzz\n”); } };

template struct loop
{ static inline void Do()
{ loop::Do(); fb::Do(); }
};

template struct loop
{ static inline void Do() {} };

////////////////////////////////////////////////////////////////

int main(int argc, char* argv[])
{
loop::Do();
return 0;
}

321. Alex Oren - June 6, 2007

Trying again:

////////////////////////////////////////////////////////////////

#include <stdio.h>

#if defined(_MSC_VER) && _MSC_VER >= 1300
#define inline __forceinline
#endif

////////////////////////////////////////////////////////////////

template<bool mod3, bool mod5, int I> struct fb
{ static inline void Do() { printf(”%i\n”, I); } };

template<int I> struct fb<true, true, I>
{ static inline void Do() { printf(”fizzbuzz\n”); } };

template<int I> struct fb<true, false, I>
{ static inline void Do() { printf(”fizz\n”); } };

template<int I> struct fb<false, true, I>
{ static inline void Do() { printf(”buzz\n”); } };

template<int I> struct loop
{ static inline void Do()
{ loop<I-1>::Do(); fb<I%3==0, I%5==0, I>::Do(); }
};

template<> struct loop<0>
{ static inline void Do() {} };

////////////////////////////////////////////////////////////////

int main(int argc, char* argv[])
{
loop<100>::Do();
return 0;
}

////////////////////////////////////////////////////////////////

322. Angus Lepper - June 6, 2007

C99:

#include <stdio.h>
#define p(t,s) if(i%t)printf(”s”)
void main(){for(int i=1;i<101;++i){p(15,Fizz-Buzz)&&continue;p(3,Fizz);p(5,Buzz);}}

I’m sure it’s possible to get it shorter but I’m new to this lark!

323. Geek School » Get Hired With FizzBuzz - June 13, 2007

[...] programming problem has been discussed a lot lately because apparently a lot of programmers can’t do it. I’ve never been asked this particular question in an interview; I had never heard of it [...]

324. whoknows - June 16, 2007

i see assembly is underrepresented. :(

i’m very much a beginner with arm asm and coding in general but wanted to make up for the underrepresentation of asm.. no assembler right now so i’ll give assembled code with arbitrary addresses (and of course untested). the systemcall used is only good for some systems, sry for that. :)

hey such a short code in hex.
FF 40 2D E9 01 00 A0 E3 01 10 A0 E3 94 A0 9F E5
33 00 00 EB 00 40 9A E5 03 00 51 E3 78 40 9F 05
06 00 51 E3 70 40 9F 05 09 00 51 E3 68 40 9F 05
0C 00 51 E3 60 40 9F 05 05 00 51 E3 5C 40 9F 05
0A 00 51 E3 54 40 9F 05 0F 00 51 E3 50 40 9F 05
00 50 A0 E1 01 60 A0 E1 04 10 A0 E1 00 20 A0 E3
00 30 A0 E3 00 00 A0 E3 3C 70 9F E5 0F E0 A0 E1
07 F0 A0 E1 05 00 A0 E1 06 10 A0 E1 01 10 81 E2
01 00 80 E2 10 00 51 E3 01 10 A0 23 64 00 50 E3
DE FF FF 3A FF 80 BD E8 00 00 00 00 B8 00 00 00
C4 00 00 00 D0 00 00 00 B0 00 00 00 38 BB 00 F0
00 00 00 00 00 00 00 00 42 00 55 00 5A 00 5A 00
00 00 00 00 46 00 49 00 5A 00 5A 00 00 00 00 00
46 00 49 00 5A 00 5A 00 42 00 55 00 5A 00 5A 00
00 00 00 00 1F 40 2D E9 0F 20 01 E2 0A 00 52 E3
06 10 81 22 F0 20 01 E2 22 22 A0 E1 01 20 42 22
06 00 A0 E3 92 00 00 E0 01 00 80 E0 0F 20 00 E2
30 20 82 E2 F0 30 00 E2 23 32 A0 E1 30 30 83 E2
00 4F 80 E2 24 44 A0 E1 30 40 84 E2 02 20 CA E4
02 30 CA E4 00 40 CA E5 04 A0 4A E2 1F 80 BD E8

ok..for better readibility:

loc_start
STMFD, SP! {R0-R7, LR}
MOV R0, #1
MOV R1, #1
LDR R10, [PC,#94]

loc_0
BL loc_3
LDR R4, [R10]
CMP R1, #3
LDREQ R4, [PC,#78]
CMP R1, #6
LDREQ R4, [PC,#70]
CMP R1, #9
LDREQ R4, [PC,#68]
CMP R1, #0xC
LDREQ R4, [PC,#60]
CMP R1, #5
LDREQ R4, [PC,#5C]
CMP R1, #0xA
LDREQ R4, [PC,#54]
CMP R1, #0xF
LDREQ R4, [PC,#50]
MOV R5, R0
MOV R6, R1
MOV R1, R4
MOV R2, #0
MOV R3, #0
MOV R0, #0
LDR R7, =0xF000BB38
MOV LR, PC
MOV PC, R7
MOV R0, R5
MOV R1, R6
ADD R1, R1, #1
ADD R0, R0, #1
CMP R1, #0×10
MOVCS R1, #1
CMP R0, #0×64
BCC loc_0
LDMFD, SP! {R0-R7, PC}

loc_3: crappy converting so it’ll stay in hex. :)

325. whoknows - June 16, 2007

pressed enter too fast..i mean that part is very much hard coded and so isnt nice :)

326. Anonymous - June 17, 2007

#include

int main(void)
{
int loopvar = 0; // Used to
for(loopvar = 1; loopvar

327. Anonymous - June 17, 2007

#include
int main(void)
{
int tmpvar = 0;
for(tmpvar = 1; tmpvar

328. Solarvoid » Blog Archive » First Challenge - June 28, 2007

[...] decided to start off the challenges with a dirt simple challenge: the FizzBuzz problem. Write a program that prints the numbers from 1 to 100. But for multiples of three print [...]

329. applicant tracking system - June 29, 2007

applicant tracking system

Hi. Thanks for the good read.

330. Shypy - July 5, 2007

Its amazing to see how many solutions here are incorrect too

331. tired old smart-ass programmer - July 11, 2007

one line javascript, pastable into a url (with bonus points for lack of whitespace and nested ?: usage):

javascript:for(x=0;x

332. tired old smart-ass programmer - July 11, 2007

one more time, to bypass the greater than/less than censors:

javascript:for(x=1;x!=101;x++)document.write((x%3?x%5?x:’Buzz’:x%5?’Fizz’:'FizzBuzz’)+’ ‘)

333. tired old smart-ass programmer - July 11, 2007

wow getting code to run after all the tick replacing wordpress does is difficult.

once more then, saving one more byte:

javascript:for(x=0;++x

334. stupid code tricks - July 11, 2007

4s a charm?

javascript:for(x=0;++x!=101;)document.write((x%3?x%5?x:”Buzz”:x%5?”Fizz”:”FizzBuzz”)+” “)

335. stupid code tricks - July 11, 2007

To Jan #298:

If a developer or whoever couldn’t write this code, I wouldn’t want them working with me.

It’s super dirt easy. Maybe the ‘developer’ or whoever you would let through shouldn’t be in tech.

I mean, what test should we use to weed out the ones who need handholding from the competant?

print your name three times?! set a variable called “i” to 500?

336. Sn0rt - July 12, 2007

Ummm, Brian Pew, your code:

void XORSwap(void *x, void *y)
{
*x ^= *y;
*y ^= *x;
*x ^= *y;
}

is even more dangerous than the dereferenced void pointers. Consider what happens if x == y. The XOR statements basicly zero out both pointers. Danger!!

337. Tobin Harris - July 21, 2007

Lol, intresting test question. I noticed most ruby examples just show off Ruby’s terse format. How about something a little more readable?

(1..100).each do |i|
print “\n#{i}”
print ” Fizz” if i % 3 == 0
print ” Buzz” if i % 5 == 0
end

338. Paw Prints » Blog Archive » In Denial - August 7, 2007

[...] among software practioners. Examples of the kind of thing I’m referring to can be found here and here. My personal experience would back up the sentiments that are expressed in these postings [...]

339. Cheez - August 15, 2007

76 bytes of PHP ;)

<?for(;++$n<101;){$e=($n%3)?”:fizz;$e.=($n%5)?”:buzz;echo($e)?$e:$n,’ ‘;}

340. toxik - August 15, 2007

Python isn’t readable. I have proof, and I beat Cheez in a verbose language, 70 bytes without the (unneeded) trailing newline:

for i in range(1,101):print(”Fizz”[:(i%3<1)*9]+”Buzz”[:(i%5<1)*9])or i

341. Definition of Information :: another one bites ... - August 22, 2007

[...] if you are a prospective developer please read  http://tickletux.wordpress.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/. If you can not complete this test in 10 minute, go read a book on programming and figure it [...]

342. Sam - August 23, 2007

Without knowing PL/SQL beforehand (because heck — no one’s tried it in SQL), in under ten minutes and access to the internet:

set echo on;
drop table TEMP;
create table TEMP
(text char(55), col2 number(4));
/
BEGIN
FOR i IN 1..100 LOOP
IF MOD(i,15) = 0 THEN
INSERT INTO temp VALUES (’fizzbuzz’, NULL);
ELSE IF MOD(i, 3) = 0 THEN
INSERT INTO temp VALUES (’fizz’, NULL);
ELSE IF MOD(i, 5) = 0 THEN
INSERT INTO temp VALUES (’buzz’, NULL);
ELSE
INSERT INTO temp VALUES (”, i);
END IF;
END LOOP;
COMMIT;
END;
/
select * from TEMP;

343. Four Points Cardinal » Blog Archive » FizzBuzz - August 23, 2007

[...] Using FizzBuzz to Find Developers who Grok Coding [...]

344. Old Wolf - August 24, 2007

Most posters seem to have missed the point of the variable swap test. Anyone who writes an obfuscated fragile non-portable hack fails, e.g. Brian Pew whose code doesn’t even compile, let alone work. Assuming the language doesn’t have a swap facility (i.e. pretty much limited to C or BASIC), using the temporary variable is the best solution bar none.

345. nomen - August 24, 2007

Ruby:

(1..100).each do |line|
if line % 3 == 0
print “Fizz”
end
if line % 5 == 0
print “Buzz”
end
print line unless line % 3 == 0 or line % 5 == 0
print “\n”
end

346. Dlareg - August 24, 2007

1 a = (1…101).to_a
2 changes = {5 => “Buzz”, 3=> “Fizz”}
3 changes.each do |number,word|
4 n=a.size
5 (n/number).times do |i|
6 pos = (i*number)-1
7 if a[pos].is_a? Fixnum
8 a[pos]=word+’ ‘
9 else
10 a[pos] = a[pos][0..-2]+word+’ ‘
11 end
12 end
13 end
14 p a
~

347. SlyEcho - August 24, 2007

Assembles with FASM and works in DOS (and Windows too, even Vista):

org 100h

mov cx, 0
foo:
inc cx
mov ax, cx

mov bl, 100
div bl
add al, 30h
mov [num], al
mov al, ah
xor ah, ah

mov bl, 10
div bl
add al, 30h
mov [num+1], al
add ah, 30h
mov [num+2], ah

mov dx, num
mov ah, 09h
int 21h

mov ax, cx
mov bl, 3
div bl
or ah, ah
jnz nofizz

mov dx, fizz
mov ah, 09h
int 21h
nofizz:

mov ax, cx
mov bl, 5
div bl
or ah, ah
jnz nobuzz

mov dx, buzz
mov ah, 09h
int 21h
nobuzz:

mov dx, eol
mov ah, 09h
int 21h

cmp cx, 100
jnz foo

mov ax, 4c00h
int 21h

num db ‘xxx:$’
fizz db ‘Fizz$’
buzz db ‘Buzz$’
eol db 0dh, 0ah, 24h

348. ACL - August 24, 2007

In tsql

declare @counter int
declare @output varchar(15)
set @counter = 1
while @counter < 101
begin
set @output = ”
if @counter % 3 = 0
begin
set @output = ‘Fizz’
end
if @counter % 5 = 0
begin
set @output = @output + ‘Buzz’
end
if @output = ”
begin
set @output = @counter
end
print @output
set @counter = @counter + 1
end

349. ACL - August 24, 2007

Where’s my indentation :)

350. Verm - August 25, 2007

There are way too many people here who think tests like these would have absolute answers.

It doesn’t really matter what exactly they come up with. There is a logical way to build a FizzBuzz program. You start with the loop, then put in the checks, using mod to check for multiples. If they start that way, fine, even if they forget to worry about multiples of 15.

Same with swapping two variables, except there’s not really any logical bugs to make there. If they define a third variable, assign the first number to it, assign the second to the first, and assign the third to the first, well, they seem to have a firm grasp on the concept.

If, instead of doing it sanely, they come out with some one-line amazing thing, they they’re either a very good programmer, or a moderately good one who’s read this page, so that’s fine too. (As an aside, I immediately thought of list($a,$b) = array($a,$b) in PHP too, like some others on this page. :) I do know of the XOR trick for C and other languages, but wouldn’t trust myself to be able to replicate it correctly in an interview. )

It’s when the person being interviewed doesn’t appear to know what to do or how to start that’s the warning sign.

351. L - August 25, 2007

Whoever wrote the KTHXBYE version… Nice job! Though it seems to fail to print the number if it isn’t one of the fizzbuzz numbers.

352. Ivan Tikhonov - August 27, 2007

: fizz 1+ .” fizz ” ;
: bazz 1+ .” bazz ” ;
: fizzbazz 1+ .” fizzbazz ” ;
: n 1+ dup . ;
: bange n n fizz n bazz fizz n n fizz bazz ;
: bang bange n fizz n n fizzbazz ;

0 bang bang bang bang bang bang bange drop cr bye

Yep, you need no modulus checking for fizzbuzz.

353. ACL - August 29, 2007

Another one in c# ala the Forth example above:

public delegate void Function(ref int x);
public static Function MakeFizzBuzz(string word)
{
if (word == “n”)
return delegate(ref int x)
{
x++;
Console.WriteLine(x);
};
else
return delegate(ref int x)
{
x++;
Console.WriteLine(word);
};
}
static Function n = MakeFizzBuzz(”n”);
static Function fizz = MakeFizzBuzz(”Fizz”);
static Function buzz = MakeFizzBuzz(”Buzz”);
static Function fizzbuzz = MakeFizzBuzz(”FizzBuzz”);

public static void Ten(ref int x)
{
n(ref x);n(ref x);fizz(ref x);n(ref x);buzz(ref x);
fizz(ref x);n(ref x);n(ref x);fizz(ref x);buzz(ref x);
}

public static void Fifteen(ref int x)
{
Ten(ref x);n(ref x);fizz(ref x);n(ref x);n(ref x);fizzbuzz(ref x);
}
static void Main(string[] args)
{
int x = 0;
Fifteen(ref x);Fifteen(ref x);Fifteen(ref x);Fifteen(ref x);
Fifteen(ref x);Fifteen(ref x);Ten(ref x);
Console.ReadLine();
}

354. leymoo - September 13, 2007

Surely:

1. If you were hiring for a *programmer*, you’d want them to bang out the code easily, much like people above me have done.

2. If you were hiring for a *developer*, you’d want them to ask “ok, what would you like me to do? I can code a short term quick solution or I can create a more flexible long term solution if you require. Would you be looking to possibly extend fizzbuzz in the future? Is there any more information you could provide?”
Take the information, THEN code a solution.

355. Imran - September 13, 2007

I am a programmer/developer with a masters degree and an years experience in system programming . I will take some time to write that code .. arnd 5 mins.

But if u give me question with some logic, which I know, I still take some time. Partly bcz I haven’t practised writing programs on papers. Rather I can write those on a text editor faster.

356. def essays(codecraft) » Hiring programmers - September 16, 2007

[...] looking for ways to improve the screening of candidates. There are interview coding tests link the FizzBuzz test. Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” [...]

357. martinus - October 1, 2007

% Erlang solution
-module(fb).
-export([fb/0]).

fb() ->
fb(1).

% iterate
fb(101) ->
ok.
fb(X) ->
pr(X),
fb(X+1).

% print
pr(X) when X rem 15 =:= 0 ->
io:format(”FizzBuzz\n”);
pr(X) when X rem 3 =:= 0 ->
io:format(”Fizz\n”);
pr(X) when X rem 5 =:= 0 ->
io:format(”Buzz\n”);
pr(X) ->
io:format(”~w\n”, [X]).

358. martinus - October 1, 2007

# Ruby solution
(1..100).each do |i|
if (i % (3*5) == 0)
puts “FizzBuzz”
elsif (i % 5 == 0)
puts “Buzz”
elsif (i % 3 == 0)
puts “Fizz”
else
puts i
end
end

359. martinus - October 1, 2007

The most important question is to ask them what they think about the code they have just written, this way you can find out how good he really is. E.g. about the ruby solution I would say something like this:

* No unit tests for the code, which is bad.
* the i%(3*5) is not obvious, needs a comment.
* Solution is not very general, but with the given information it is useless to generalize it more because we don’t know what generalization will be necessary in future.
* solution is not reusable because not inside a class
* hardcoded numbers are bad
* performance could be optimized by reordering statements, i%3 is the most often case.
* performance of % and if statement is probably irrelevant because io is usually the limiting factor.
* purpose of the code is unknown.

360. Drew Peacock - October 3, 2007

I refuse to believe that anyone with even the most casual understanding of a language would be unable to make their own FizzBuzz. Surely this is about how you work, and in which case I’d not want to team up with the people above who treated it as a challenge to create brilliantly terse but wholly impenetrable one-liners. Great if you’re running low on hard drive space, I guess, but not so great if you want your fellow developers to like you…

Pascal


var
N: Integer; S: String;

for N := 1 to 100 do begin
S := '';
if N mod 3 = 0 then begin
S := 'Fizz';
end;
if N mod 5 = 0 then begin
S := S + 'Buzz';
end;
if (N mod 3 > 0) and (N mod 5 > 0) then begin
S := IntToStr(N);
end;
WriteLn(S);
end;

361. FizzBuzz in Factor « Shellfish Jeans - October 7, 2007

[...] Now if you don’t know what FizzBuzz is, take a look at this: Using Fizzbuzz to find developers who Grok coding [...]

362. 100 Resources to Attract, Retain and Utilize Rock Star Programmers | MT-Soft Website Development - October 18, 2007

[...] Using FizzBuzz to Find Developers Who Grok Coding: This method recommends testing your candidates with a lowball problem to find out their competency. [...]

363. Scott Hanselman's Computer Zen - The Weekly Source Code 9 - WideFinder Edition - October 23, 2007

[...] many folks are focusing on Item #5. Either way, it’s a heck of a lot more interesting problem than FizzBuzz and worth adding to your interview arsenal [...]

364. Terry Smith - October 24, 2007

Ruby

(1..100).each{|n|
puts n unless n % 3 ==0 unless n % 5 == 0
puts “Fizz” if n % 3 ==0 unless n % 5 == 0
puts “Buzz” unless n % 3 ==0 if n % 5 == 0
puts “FizzBuzz” if n % 3 ==0 if n % 5 == 0
}

365. Mike Swierczek - December 7, 2007

I didn’t know a damn thing about computers when I got to college. I took a few simple CS courses as an undergrad. It’s senior year, I’m kicking around the idea of grad school, so I go for Software Engineering. I’m accepted (no GRE subject test required), and find out the program is about the Mythical Man Month, formal proofs that functions will exit, project management, Design Patterns, and so forth.

I think most of the people here were immersed in this culture, some at an early age. I didn’t even realize how many free compilers and online tutorials for different tasks and languages existed. I was a fish out of water, and I didn’t even know how to get back into the ocean.

I snared a first job on the strength of my grades and good high level discussion of concepts, and then proceeded to be an anchor on my team for a solid six months and then maybe just floating driftwood for six more. That was six years ago, and now FizzBuzz is quite easy.

I’m sure there are interviewees that are hoping to lie their way through the process. But there are also some people new to the field – some young, some not – that can be damn good developers if you give them some time. I’m not saying you should hire them, I’m just asking you to cut them some slack. Maybe encourage them to pick up some good books and work through the examples before they interview anywhere else.

366. sclv - December 18, 2007

swapping two variables, declaring *none*: uncurry (flip (,))

367. Bony - December 21, 2007

This is the greates article about Fizz-Buzz .

368. JavaGuy147 - December 29, 2007

the C way of swapping two variables without a temp var is very simple. For those who don’t know it:

a^=b^=a^=b;

you can also use adding/subtracting the variables in the right order but I don’t think the method is worth showing

369. rille111 - January 4, 2008

Just to show you lot how simple and nice VB.NET is, i can do this in 3 lines.

For i As Integer = 1 To 100 Step 1
Console.WriteLine(i & “: ” & IIf(i Mod 3 = 0, ” fizz”, “”) & IIf(i Mod 5 = 0, ” buzz”, “”))
Next

370. MT - January 6, 2008

# Fizzbuzz in ruby
def fizzes(i); i % 3 == 0; end
def buzzes(i); i % 5 == 0; end
def boring(i); not(fizzes(i) or buzzes(i)); end
(1..100).each do |i|
print “Fizz” if fizzes(i)
print “Buzz” if buzzes(i)
print i if boring(i)
puts
end

—-

# Reading numbers from file and totalling, may fail if file
# contains blank lines or non-numerics.
File.readlines(”numbers.txt”).collect { |line| line.chomp.to_i }.inject { |t, i| t+i }

—-

# Convert from number to string without using
# built-in converters like printf and variable interpolation.
# ?0 is the ASCII value 0, and the chr() method gives the
# string equivalent of the ASCII value.
n = 436
str = “”
while n>0
digit = n % 10
n = (n-digit) / 10
str = (?0 + digit).chr + str
end
puts str

—-

Not sure why I’m posting the result, except I enjoyed thinking about albeit simple little challenges like this; a welcome relief from the complexities of real projects. Besides, I enjoyed reading some of the other people’s replies.

Some people seem to be reading too much into the purpose of the OP’s test. If your programmer / developer can’t manage these simple algorithms then that is certainly useful information to reveal. How you weigh that in with rest of your presumably extensive interview information depends entirely on your goals and requirements. A useful little test if you ask me.

371. Krenzel.info » Blog Archive » FizzBuzz - January 7, 2008

[...] wrote a great post titled Why Can’t Programmers.. Program?. The author references another post by Imran which introduces what is now a commonly referenced programming “challenge” [...]

372. adrien - January 9, 2008

here is a c# one liner solution
for (int x = 1; x <= 100; x++) Console.WriteLine(x + “:” + (x % 3 == 0 ? “Fizz” : “”) + (x % 5 == 0 ? “Buzz” : “”));

373. waseem - January 9, 2008

#include

main(){
int n;
for(n=1;i<=100;n++){
if(n%3==0 && n%5==0)
printf(”FizzBuzz\n”);
else if(n%3==0)
printf(”Fizz\n”);
else if(n%5==0)
printf(”Buzz\n”);
else
printf(”%d\n”,n);

}//for

}//main

374. Rudolf - January 12, 2008

Ha, I asked a intern at my company yesterday, in 3 minutes he came up with this PHP piece.

for($i=1; $i < 101; $i++) {
echo ( $i % 15 ? $i % 3 ? $i % 5 ? $i : “Buzz” : “Fizz” : “FizzBuzz” ).”\n”;
}

375. McWow the busy - January 15, 2008

[...] 20x more productive than the guy in the 5- area. But then again, that 5- area is why we end up with FizzBuzz. 20x is even being generous to the guys at the bottom. I’d have no problem believing infinity [...]

376. Rich - January 17, 2008

A C#/LINQ centered attempt

using System;
using System.Linq;
using System.Collections.Generic;

public class FizzBuzzer
{
delegate string FizzBuzz(int i);

public List GetFizzBuzzList()
{
FizzBuzz r = delegate(int i) { return (i % 5 == 0 ? “Fizz” : “”) + (i % 3 == 0 ? “Buzz” : “”); };
var q = from f in Enumerable.Range(1, 100) select r(f);
return q.ToList();
}
}

//…
foreach(string s in new FizzBuzzer().GetFizzBuzzList())
{
Console.WriteLine(s);
}

377. Someguy - January 18, 2008

I am forced to wonder if Mitch Silverman, post #4, has been driving down dark country roads at 80 mph… Backwards?

“.. or did (s)he get that deer in the taillights look in his/her eyes?

378. robbat2 - January 27, 2008

90 seconds.

#include <stdio.h>
int main(int argc, char** argv) {
int i; for(i = 1; i<=100; i++) { if(printf(”%s%s”, (i % 3) ? “” : “Fizz”, (i % 5) ? “” : “Buzz”) < 4) printf(”%d”, i); printf(”\n”); } }

But shoot me for abusing the return value of printf.

379. RS - January 27, 2008

They’re teaching kids Java…. at least at the school I’m at, it’s all theory too, not actual practical programming. Great for students that want to become CS teachers, but bad if they want to work for an actual company.

90 seconds.

<?php
for ($i=1; $i

380. RS - January 27, 2008

$i++) {
if (($i % 3 == 0) && ($i % 5 == 0)) {
echo “FizzBuzz \n”;
} elseif ($i % 3 == 0) {
echo “Fizz \n”;
} elseif ($i % 5 == 0) {
echo “Buzz \n”;
} else {
echo “$i \n”;
}
}

381. Mikachu - January 27, 2008

there are a lot of comments, so maybe someone mentioned this already: you have to check if a==b in your xor swap functions or you will just clear both of them, as a^a == 0.

382. Aigarius - January 27, 2008

a = [0,0,"Fizz",0,"Buzz","Fizz",0,0,"Fizz","Buzz",0,"Fizz",0,0,"FizzBuzz"]
for i in range(1,101):
print a[i%15] ? i, a[i%15]

383. Sael - January 29, 2008

I got hired in the summer ‘07, and was put through three tests besides the usual talky-talky stuff for the interview.

One was writing a stored procedure in T-SQL.

Next, doing a bit of UML – heck, just pseudo-sketching the “basket”-part of a web shop did the trick actually.

And last, doing FizzBuzz in C#. I was asked first if I had ever heard of it before, which I truthfully answered no to. In essence, I wrote the code in hand (taking about 1,5 minute since it takes forever to write readable handwriting these days).

I was later told that although my solution was almost perfect (could’ve been more tightly written), I was chosen over other candidates because of the speed of solving it, as well as actually listening and chit-chatting while doing it. See, the company used it more as a test of a person’s ability to work in an abstract environment – talking about stuff while doing it at the same time was the real test.

Still, they told me that they threw candidates out as soon as they displayed a lack of abilities in any of the three tests (since they are so simple).

BTW, this was in Denmark, and my education which was completed in the Spring of ‘07 isn’t in Computer Science as such, but more just a special education to become a “coding monkey” of sorts – that is, having a practical approach to code, instead of a theoretical as CS usually is over here.

384. Fizz, buzz, fizzbuzz | Libin Pan - February 7, 2008

[...] Imran On Tech: Using FizzBuzz to Find Developers who Grok Coding [...]

385. FizzBizz in JavaScript : minutiae - February 11, 2008

[...] About a year ago someone put up a blog post on using using FizzBizz to find developers who grok code. [...]

386. Flashtastic - February 12, 2008

FizzBuzz in ActionScript:

for (var i = 1; i<=100; i++) {
if ((i%5) == 0 && (i%3) == 0) {
trace(i+” FizzBuzz”);
continue;
} else if (i%5 == 0) {
trace(i+” Buzz”);
} else if (i%3 == 0) {
trace(i+” Fizz”);
} else {
trace(i);
}
}

387. joker - February 13, 2008

I know the answer
print(1);
print(2);
print(Fizz);
print(4);
print(Buzz);
print(Fizz);
print(7);
print(8);
print(Fizz);
print(Buzz);
print(11);
print(Fizz);
print(13);
print(14);
print(FizzBuzz);
print(16);
print(17);
print(Fizz);
print(19);
print(Buzz);
print(Fizz);
print(22);
print(23);
print(Fizz);

ok I am just too lazy to complete this joke.

388. james mckay dot net » Pro JavaScript Techniques - February 16, 2008

[...] Personally, I’ve felt a bit disappointed by this. I’ve said before that I think of JavaScript as the new Scheme — so with that in mind, anything that treats it as if it were merely client-side PHP will naturally be something of a disappointment. Perhaps this is a case of quidquid latine dictum sit, altum viditur on my part, but I like to use closures, lambdas, iterators, generics, Linq and so on in my code to maximum effect. I am also firmly of the opinion that every professional developer needs to be familiar with these concepts too — after all, they show that you have the kind of mind that can handle the complexities of software development, and won’t stumble over the FizzBuzz problem. [...]

389. How to talk about Data Structures : mcherm.com (beta) - February 17, 2008

[...] what I would consider the most fundamental of programming skills. Some people have suggested using FizzBuzz (a trivial programming exercise) as a filter; what I use is a discussion of data [...]

390. Missing Features » Are You An Efficient Programmer? - February 25, 2008

[...] Most programmers are really bad at programming. Grab 10 random students from a computer science masters program and your correspondent will happily wager a case of Brooklyn Brewery Chocolate Stout that at least nine of those programmers will fail a basic programming task. [...]

391. mdp - February 27, 2008

Hope this code renders properly.
Does the plaintext tag work?

I only just heard about FizzBuzz, and while there
are implicit sieves posted, there does not seem
to be an actual sieve.

/*
Write a program that prints the numbers from 1 to
100. 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”.
*/

#define SIEVE_SIZE 101

int main (void)
{
int retval = 0;
int idx;
int it;
char sieve[SIEVE_SIZE];
int fizz_mask = 0×01;
int buzz_mask = 0×02;

for(idx = 0; idx < SIEVE_SIZE; ++idx) sieve[idx] = 0;
for(idx = 0; idx < SIEVE_SIZE; idx += 3) sieve[idx] |= fizz_mask;
for(idx = 0; idx < SIEVE_SIZE; idx += 5) sieve[idx] |= buzz_mask;
for(idx = 1; idx < SIEVE_SIZE; ++idx)
{
if((it = sieve[idx]) == 0) printf(”%3d\n”, idx);
else
{
if((it & fizz_mask) == fizz_mask) fputs(”Fizz”, stdout);
if((it & buzz_mask) == buzz_mask) fputs(”Buzz”, stdout);
fputc(’\n’, stdout);
}
}

return retval;
} /* main */

392. FizzBuzz To Infinity « Better Software. Better Science. Better Sense. - March 1, 2008

[...] in Software tagged fizzbuzz at 1:12 pm by mj If you’re like me, the first time you heard the FizzBuzz programming interview meme, you tried it yourself in your favorite [...]

393. Justin Blaauw - March 15, 2008

When I followed the link to FuzzBuzz it vaguely rang a bell. Then on reading the site, I remembered – I had to do this test as part of an interview process for a place called GuruHut in South Africa. I creamed it but was wondering why they would ask someone like me – a 7 year experienced Java developer to write this code. Now I understand : )

394. C40’s Blog » Ruby và thú vui “code 1 dòng” - March 26, 2008

[...] Bài này có thể gọi là “siêu dễ”. Thế nhưng mà phần lớn dân tốt nghiệp lập trình không giải được bài này (hô hô). [...]

395. Paul - March 27, 2008

I didn’t read all the posts but many solutions repeat the multiple test with the modulo operator. Why test i mod 3 then i mod 5 and also test i mod 3 AND i mod 5 again.
Why not just:

for (i = 1; i <= 100;i++)
{
mod3 = 0
mod5 = 0

if (i % 3 == 0)
{
mod3 = 1
print(”Fizz”)
}
if (i % 5 ==0)
{
mod5 = 1
print(”Buzz”)
}
if (!(mod3 || mod5))
print(i)
}

But one problem is that for sequences like 9,10, or 24,25, etc FizzBuzz is printed because 9 is a multiple of 3 and 10 is a multiple of 5. So FizzBuzz gets printed even though neither 9 or 10 are multiples of 3 AND 5. That would throw me on a interview test because it would make me think its a trick question and that the only time FizzBuzz should get printed is if a number is a multiple of 3 AND 5, not when there are consecutive numbers that are mutliples of 3 and 5 respectively that may also print FizzBuzz. The time spent looking for the trick or gotcha would take more than a minute, and I am kicked out as a bad programmer because it took longer than a minute to finish such a simple problem :(
There are no simple problems.
Paul

396. joe - May 18, 2008

(define (fizzbuzz n)
(let ((test (cond ((= 0 (modulo n 15)) “Fizzbuzz”)
((= 0 (modulo n 5)) “Fizz”)
((= 0 (modulo n 3)) “Buzz”)
(else n))))
(if (= n 0) (list n)
(cons test (fizzbuzz (- n 1))))))

(map print (fizzbuzz 100))

397. Keber - June 2, 2008

Hi,

I gave this problem to my students of two programming’s first course . One group, with teacher’s help, answered it in about two hours, most of them making unnecessary comparisons. In the other group, without help, about 25% step out the question, and about 10~15% gave an acceptable answer.

398. Anonymous - June 15, 2008

var i=0;

while (i < 100) {
i++;
if (i%3==0 && i%5==0) {
fb=”Fizzbuzz”;
document.write(fb + “, “);
} else if (i%3==0) {
f=”Fizz”;
document.write(f + “, “);
} else if (i%5==0) {
b=”Buzz”;
document.write(b + “, “);
} else {
i=i;
document.write(i + “, “);
}
}

399. Anonymous - June 15, 2008

Written in Javascript, forgot to include that.

400. Interviews : Please Stop Yelling - June 16, 2008

[...] FizzBuzz. A small problem that someone used to in an interview to test a programmer’s skills. Using FizzBuzz to Find Developers who Grok Coding It’s worth reading the comments on this [...]

401. Eric - June 21, 2008

I stumbled on this thread while reading stuff on Ruby (trying to understand why it’s so “popular”). It’s so hard to read, i bet you lose any gain you could get from it’s supposed fast developpement abilities! ah! ah!;)

This post what interessing in that regard, to see a few exemple of different languages for the same very simple problem.

The solution someone posted in Basic (i havent check if it’s valid) was to me the best exemple of how someone should answer such question in a interview (on paper), “pseudo-code” style:

for i = 1 to 100
if i mod 3 = 0 then print “Fizz”
if i mod 5 = 0 then print “Buzz”
if i mod 3 > 0 and i mod 5 > 0 then print str$(i)
next

(the str$ is a bit horrible… but it’s still readable overall)

Reading some of the other samples, it’s no surprise so much of the developpers have to work at night to get their job done! :)

402. :l: / Obfuscated FizzBuzz - June 26, 2008

[...] I read the original fizzbuzz article, I have suggested it to a couple people as an interview question and it seems to do its job as a [...]

403. Eric - June 28, 2008

“:l: / Obfuscated FizzBuzz”

I’m not sure what you have understanded better than everyone else!

Just for the fun of it (the basic version of the other guy was bad):

This version in realbasic has around 189 tokens (wich include all the formatting characters for indentation (realbasic autoformat), scope correct variable declaration and also valid output (at least to what i understand — the description of the problem doesnt specify if the print had to be on a new line, the code could be shorter otherwise!). Even with a logical hack/optimisation, it’s still readable!

dim i as integer
for i = 1 to 100
dim t as string
if i mod 3 = 0 then t=t+”Fizz”
if i mod 5 =0 then t=t+”Buzz”
if t=”" then
t= str(i)
end if
print t
next

Still shorter than your obfuscated version (around 216 chars)…. :b

And in Macromedia lingo, from memory as i dont have the environnement:

repeat with i from 1 to 100
t=”"
if i mod 3 = 0 then t=t&”Fizz”
if i mod 5 =0 then t=t&”Buzz”
if t=”" then
t= i
end if
put t
end repeat

404. Wang-Lo - July 10, 2008

That’s not a short program. THIS is a short program:

Digital Equipment Corporation PDP-8 FIZZBUZZ program:
118 12-bit words (equivalent to 177 modern 8-bit bytes)
ON THE BARE METAL INCLUDING THE DEVICE DRIVER!
These 118 words are the only ones that need to be in
the entire computer — no OS, no BIOS, nothing else.

And this is on a CPU that not only doesn’t have a FPP,
it doesn’t even have hardware multiply and divide.
In fact, it doesn’t even have a SUBTRACT instruction.

So don’t be telling me about your “short” 80-byte
scripts that can only live in a 256MB OS with a
runtime library the size of a two-car garage. Punks.

/ FIZZBUZZ PROGRAM COPYRIGHT 2008 WANG-LO

* 200 / STANDARD START LOC

/ ****** THE MAIN PROGRAM ******

CLA
TLS

DCA IVALUE / PRESET DISPLAY VALUE
CLA CLL CMA RTL / PREP MOD 3 SIEVE
DCA MOD3CT
TAD M5 / PREP MOD 5 SIEVE
DCA MOD5CT
TAD M100 / PRESET LOOP COUNTER
DCA LOOPCT

MAINLP, ISZ IVALUE / DISPLAY 1..100 NOT 0..99
ISZ MOD3CT
JMP NOTM3 / ITS PLAIN OR BUZZ
CLA CLL CMA RTL / ITS FIZZ OR FIZZBUZZ
DCA MOD3CT / RESET MOD 3 SIEVE
ISZ MOD5CT
JMP NOTM5 / ITS FIZZ
TAD M5 / ITS FIZZBUZZ
DCA MOD5CT / RESET MOD 5 SIEVE
JMS PRTEXT
106 / F
151 / i
172 / z
172 / z
142 / b
165 / u
172 / z
172 / z
0
JMP DONELP

NOTM5, JMS PRTEXT
106 / F
151 / i
172 / z
172 / z
0
JMP DONELP

NOTM3, ISZ MOD5CT
JMP NOTANY / ITS PLAIN
TAD M5 / ITS BUZZ
DCA MOD5CT / RESET MOD 5 SIEVE
102 / B
165 / u
172 / z
172 / z
0
JMP DONELP

NOTANY, TAD IVALUE
JMS PRNUMB

DONELP, JMS PRCRLF / ONE INERATION PER LINE
ISZ LOOPCT
JMP MAINLP
HLT / STOP
JMP .-1 / STOP MEANS DONT GO AGAIN

M100, 7634 / NUMBER OF LINES TO PRINT
M5, 7773

IVALUE, 0
MOD3CT, 0
MOD5CT, 0
LOOPCT, 0

/ ***** THE RUNTIME LIBRARY *****

/ PRINT A POSITIVE INTEGER (IN RANGE 0..4095)
PRNUMB, 0
DCA SVNUMB / SAVE VALUE TO BE PRINTED
DCA LZFLAG / CLEAR LEADING-ZERO FLAG
JMS PRDDGT / 1ST DGT IF NOT LEADING ZERO
6030 / -1000
JMS PRDDGT / 2ND DGT IF NOT LEADING ZERO
7634 / -100
JMS PRDDGT / 3RD DGT IF NOT LEADING ZERO
7766 / -10
TAD SVNUMB / 4TH DGT
TAD KA0
JMS PRCHAR
JMP I PRNUMB
PRDDGT, 0
DCA NUMBCT / CLEAR DIGIT VALUE
PRDGLP, TAD I PRDDGT / SUB DGT WGT FROM NUM VALUE
TAD SVNUMB
SPA
JMP PRDGEX / TOO FAR — GO PRINT
ISZ NUMBCT / COUNT WGT-SUBTRACTION
DCA SVNUMB / RESTORE DIMINISHED VALUE
JMP PRDGLP
PRDGEX, CLA / DISCARD OVERDIMINISHED VAL
TAD NUMBCT / EXAMINE WGT-SUBTR COUNT
SZA
JMP PRDGDO / NOT ZERO — PRINT IT AND SET FLAG
TAD LZFLAG / ZERO — FLAG SET?
SZA
JMP PRDRTN / NO, LEADING ZERO — DONT PRINT
PRDGDO, TAD KA0 / YES — PRINT IT
JMS PRCHAR
ISZ LZFLAG / SET LEADING-ZERO FLAG
PRDRTN, ISZ PRDDGT / EXIT @+1
JMP I PRDDGT
KA0, 60
SVNUMB, 0
LZFLAG, 0
NUMBCT, 0

/ PRINT A TEXT MESSAGE (IMMED Z-TERM 7BIT ASCII)
PRTEXT, 0
TAD I PRTEXT / GEXT NEXT TEXT LEXT
ISZ PRTEXT
SNA / TEXT MUST END WITH ZERO
JMP I PRTEXT / RETURN TO LOC AFTER TEXT
JMS PRCHAR
JMP PRTEXT+1

/ PRINT END OF LINE
PRCRLF, 0
TAD K15 / CR
JMS PRCHAR
TAD K12 / LF
JMS PRCHAR
JMP I PRCRLF
K15, 15
K12, 12

/ ****** PRINTER DEVICE DRIVER ******

PRCHAR, 0
PSF
JMP .-1
PLS
CLA / SOME LPT DONT CLR AC
JMP I PRCHAR

405. Eric - July 16, 2008

And how do you pull that during a one hour interview? :b

406. Colin Alston - August 7, 2008

Discrete logic plus listcomp in Python.

[ (i%3 or i%5) and (i%3 and (i%5 and i or 'Buzz') or 'Fizz') or 'Fizz-Buzz' for i in range(1,101)]

407. TXGruppi » Archive » Teste seus códigos de qualquer lugar - August 11, 2008

[...] this paste permanently”. O site também tem exemplos de “Hello World” e “Fizz-Buzz” em cada linguagem. Outra funcionalidade é a criação de uma página para projetos, a mais [...]

408. TheDude - September 8, 2008

Script Injection Alert!

409. JB - September 15, 2008

The next questions should be….

OK, now it’s tomorrow and the customer is changing the requirements…

Now change it so that you can add support for any foreign language translation of “Fizz”, “Buzz” or “FizzBuzz”. It should accept languages that are read right-to-left (Hebrew) or require double byte character sets (Chinese).

And be sure to write it so that the number doesn’t need to be 100 but needs to be a positive integer. Wait, the customer just changed this as we were talking, it needs to be prime. Wait…..change that requirement to be a prime that is inferred from a message sent by another system at random intervals…..

410. markus - September 15, 2008

@ 401. Eric

You talk crap, but your program would seem to print fizzbuzz fizz-buzz on 15. You lose the interview.

411. recursive - September 16, 2008

@ 410. markus

How are you getting that? It only prints one of each of “fizz” and “buzz” for 15.

412. Bill G - September 18, 2008

I couldn’t see vbscript version – so here goes from rusty memory:

Option Explicit

Dim i

For i = 1 to 100
If i Mod 15 = 0 Then
Response.Write “FizzBuzz”
Else
If i Mod 3 = 0 Then
Response.Write “Fizz”
ElseIf i Mod 5 = 0 Then
Response.Write “Buzz”
Else
Response.Write i
End If
End If
Next

Do I win a prize for the longest snippet?

413. Bill G - September 18, 2008

Snippet envy??

414. Why So Confused? « learning the art of programming - September 27, 2008

[...] its syntax and write non-trivial programs in a week. I need to learn to do simple things first like Fizzbuzz and then go for the smaller challenges in Project Euler and then onto bigger [...]

415. Mediocre-Ninja.blogSpot.com - October 17, 2008

#fizzbuzz.rb
a = nil, ‘fizz’, ‘buzz’, ‘fizzbuzz’
1.upto(100) { |a[0]| puts a[(a[0]%3 == 0 ? 1 : 0) + (a[0]%5 == 0 ? 2 : 0)] }

416. Arun Saha - October 27, 2008

I would do the following implementation. Its little lengthy than some other already posted, but it
– is eaxy to extend e.g. “Jazz” for multiples of 7
– does not use modulo operator, which “may” be expensive

void
fizzbuzz() {

unsigned int i, nextFizz = 3, nextBuzz = 5, situation;

for( i = 1; i <= 100; i++ ) {

situation = 2 * ( i == nextBuzz ) + ( i == nextFizz );

switch( situation ) {
case 3:
printf( “FizzBuzz\n” );
nextFizz += 3;
nextBuzz += 5;
break;

case 2:
printf( “Buzz\n” );
nextBuzz += 5;
break;

case 1:
printf( “Fizz\n” );
nextFizz += 3;
break;

case 0:
printf( “%u\n”, i );
break;
}
}
}

417. Erik - November 6, 2008

C
C FIZZBUZZ IN FORTRAN IV
C
IMPLICIT INTEGER (I-N)
DO I = 1, 100
IF (MOD(I,3).EQ.0) WRITE(1,10)
IF (MOD(I,5).EQ.0) WRITE(1,20)
IF ((MOD(I,3).NE.0).AND.(MOD(I,5).NE.0)) WRITE(1,30) I
WRITE(1,40)
CONTINUE
STOP
10 FORMAT(’FIZZ’,Z)
20 FORMAT(’BUZZ’,Z)
30 FORMAT(I3,Z)
40 FORMAT(”)
END

418. Eric - November 19, 2008

@410. markus

The code on 401 was not mine!

@403 is doing the job exactly like it should.

“Write a program that prints the numbers from 1 to 100. 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”.”

In fact, i even tested the algorithm in Actionscript:

var tString:String;

for (var i:Number=1;i <=100; i++)
{
tString=”";
if (i%3==0)tString=tString+”Fizz”;
if (i%5==0)tString=tString+”Buzz”;
if (tString==”") tString=String(i);

trace(tString);

}

The output being:

11
Fizz
13
14
FizzBuzz
16
17

So, YOU talk crap! Waiting for your code answer! ah! ah! :)

419. Ablog » FizzBuzz Improved - November 24, 2008

[...] I explain how and why we make prospective hires write code on a whiteboard. In a similar vein, Imran on Tech posts about making developers write FizzBuzz. Several of us read the article, got caught in the, “Huh? That doesn’t sound hard. Let [...]

420. Test Your Might! « Software Bloat - November 30, 2008

[...] than one language may be appropriate, they choose the most expressive language available. Consider The FizzBuzz Problem (a simple “weed-out” problem given to interview candidates) which has been stated [...]

421. practice « Dion’s Weblog - December 8, 2008

[...] Here’s the infamous FizzBuzz: [...]

422. Lithping Lambda - December 24, 2008

1. Mmm.. I did not see immediately how to do it in a roundabout and convoluted way while using some intricate programming techniques (that’s what this challenge was about, right?)

But finally I made it, I made it marginally more convoluted, like this: Code:

#!/usr/local/bin/newlisp

(for (x 1 100 1)
(or
(and (set ‘three (= 0 (% x 3))) (println “Fizz”))
(and (= 0 (% x 5)) (or
(and three (println “FizzBuzz”))
(println “Buzz”) ))
(println x)
)
)
(exit)

2. .. but then thought again. The true corporate solution would be this:
Code:

(println 1)
(println 2)
(println “Fizz”)
(println 4)
(println “Buzz”)
(println “Fizz”)
(println 7)

Note to the team leader: “please forward this code to a junior member of the team to complete typing”

Note to the manager: “I have submited perfectly working code which should meet all deadlines. The team will be working on the next version as time permits to improve satisfaction in case of customer requests for number of items other than one hundred”

3. OOP.
By the time work on the second version started, however, it was mandated that all code followed the Object Oriented Paradigm.
So, in accordance with the principle that objects reflect real life entities, the program now generates 100 “Child_player” objects, which are passed request_messages from the Game_Master object (the supervisor pattern?). Each of the objects’ reply to the Fizz-Buzz question is then collected and formatted centrally for dispatch to the expernal requesting entity.

..mmm working on it.

4. Just got an e-mail from the management.
Version 3 is supposed to be a network distributed solution. Each of the 100 children objects will be converted to a freely-flying persistent network agent, which maintain their internal state and are able to change their chairs so to say, while still engaged in the game. Results are to be sent to a company overseas branch and support integrity checking and strong encryption

Help!

5. FINALLY: A truly geeky solution.

.. but there was in this company in the farthest corner of the room where all programmers sat a tiny office, and it was occupied by an old grumpy unix geek, who was actually the company system administrator.
As his servers buzzed on for the third year without a single reboot and his monitoring scripts notified him of the problems about 15 minutes before they hit, he had all the time on his hands to play with his favourite geeky toys. And one of such toys was functional programming.

So in half the time it took the company testing department to discover that typo in the customer report which turned an innocuous phrase into a grossly indecent one (slashing the company revenues and resulting in a couple of lawsuits by enraged budgerigar owners, all luckily settled out of court), he produced his own truly functional solution to the Fizz-Buzz problem.

It ran like this: Quote:

The input stream (potentially infinite, but reduced to the first 100 numbers for the sake of testing) is processed lazily, i.e. one item at a time.
The program runs 2 lazy generators in two coroutines, one spits numbers which are consequtive multiples of 3, the other one bakes multiples of 5 (or any other given numbers). So, once the generator is appropriately kicked, a new member of the virtual “list” is generated, the next multiple to check against.

The main program therefore checks each input value from that (infinite) input stream for _equivalence_ with the current 3-list and 5-list members by ping-ponging to the coroutine.
Once the equivalence is found, the 3-list or 5-list generator(s) lazily produce a next number for comparison.

But, to speed things up and save on the coroutine invocation, the numbers from those lazy generators are of course memoized, thus cutting up the needed time and improving performance

Everyone marvelled at the sight of the sysadmin prog crunching Fizz-Buzzer player numbers in the gazillions and the generality of the solution allowing it not to slow down even if 312345912358 and 512309482093481209358340 were the needed as multiples, but no one understood a thing, and management turned it down as totally unmantainable.

The geek then sligtly changed some output parameters of his script and posted it on the Internet, where it became popular as a computer game called “Squash the Bill”.

Has anyone seen it recently? Could you post the source code here?