FizzBuzz and Problem Finding

Posted in Coding, IT by Will on 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.

Reading through the “Fizz-Buzz” problem they had, I thought to myself, “So, what would I do if presented with this”.

Something like this popped into my head:

        For i As Integer = 1 To 100
            If (i Mod 3) = 0 Then _
                    Console.WriteLine("Fizz")
            If (i Mod 5) = 0 Then _
                    Console.WriteLine("Buzz")
        Next

Then I re-read the spec and realised, hey, I don’t actually have it outputting the numbers, and it ouputs multiples of 3 and 5 (such as 15) with a linebreak between them.  (Is this iterative development?)

So, it became (again, in my head - which is scary):

        For i As Integer = 1 To 100
            If (i Mod 3) = 0 AndAlso (i Mod 5) = 0 Then
                Console.WriteLine("FizzBuzz")
            ElseIf (i Mod 3) = 0 Then
                Console.WriteLine("Fizz")
            ElseIf (i Mod 5) = 0 Then
                Console.WriteLine("Buzz")
            Else
                Console.WriteLine(i)
            End If
        Next

So, reading through a solution posted by James on Jeff Atwood’s post made me feel smart (they’re basicly identical). After all, if most of these comp-sci people couldn’t figure it out, then I wasn’t as bad a coder as I had feared. (I know I’m not a top-class developer).

Then someone by the name of Toepopper writes “I once interviewed a candidate for a VBA job … whom I asked to swap two variable contents without using a temp variable.”

That one had me stumped.  I wouldn’t have even thought of the excel “answer” that Toepopper said someone tried - but the problem would still remain.  

I guess this is the point where a lack of formal education in comp sci (or experience developing in very memory limited environments) really comes home to roost. However, I could have given an answer by doing a quick google search. Is that acceptable? To some (like Toepopper) this is probably not acceptable - but for me, I’d get the answer, albeit slightly slower (the first time) than someone else with that formal education or background.

The issue comes when someone asks you to do that in an interview, without ‘net access.

One Comment

  1. Stripes replied:

    I have a vague recollection of doing the “swap two variables without introducing a 3rd” in collage, but I had seen it before (and after). I don’t think I ever had it as an interview question though.

    My guess is at an interview it probably isn’t a make-or-break question, but a “can he get 8 out of 10 of these”, or “can I walk them through to the answer”?

    March 19th, 2007 at 7:20 pm. Permalink.