FizzBuzz

So, there's this thing called the FizzBuzz test, which it turns out that a lot of people applying for "programmer" jobs can't pass. In a spirit of adventure, I had a go at it myself:
(require (lib "1.ss" "srfi")) ;iota
(define (fizz-buzz n)
(let ((multiple-of-three (= 0 (modulo n 3)))
   (multiple-of-five (= 0 (modulo n 5))))
(if multiple-of-three
   (display "fizz"))
(if multiple-of-five
   (display "buzz"))
(if (not (or multiple-of-three multiple-of-five))
   (display n))
(newline)))

(for-each (lambda (n)
       (fizz-buzz (+ 1 n)))
     (iota 99))
It took me a bit longer than the "under a couple of minutes" that Imran wants a good programmer to do it in (but this is not written on a piece of paper, this was written in DrScheme, and I ran it, and it works) but less time than the 15 minutes that "self-proclaimed senior programmers" sometimes take--which I suppose makes me a middling-good semi-senior programmer, which is about right.

The discussion of this on CodingHorror pulls together a lot of amazed reactions from various places, but none of them quite seem to grasp the nettle which is not so much that there a lot of really bad programmers around, but that there are a lot of IT professionals around who apply for "programmer" jobs even though their work experience doesn't actually include any programming.

This is a relatively new thing, and seems to be different from the old "data processing" vs "real programming" divide: I'll bet a grizzled COBOL walloper could polish off the fizzbuzz problem pretty quickly (and it would probably compile first time, too) But if your "IT" job consists, as many do these days, of using rich visual tools to script up interactions between enterprise components supplied by the tool vendor, or maybe filling in the templates used to generate the code that generates the code that gets scripted up by someone else, or any one of a number of other similar things then you certainly work at building IT systems, but what you do is not programming. And really, that's OK, kind-of. It isn't anything to be ashamed of, in and of itself.

The economic and cultural conditions that have caused such dreary jobs to exist and be worth having perhaps are something to be ashamed of, but this is not the fault of the people filling the jobs.

 

Fitted up

Anyway, back in the late 1990's when I was persuing a post-grad course in Software Engineering there was talk of "component foundaries", and the idea that there would be people like the toolmakers and machinists or yore working in these foundaries. And then there would be something like fitters who would assemble working systems out of those components. Please accept my apologies if you are reading this in a country that has not turned its back on manufacturing (except in certain specialized areas) and still know what I'm talking about. Being a fitter was a fine profession, back in the day, but no-one would hire a fitter as a toolmaker (although a fitter might aspire to be and retrain as, a toolmaker). This change now seems now to have happened in the IT industry, without being widely recognised.

Maybe we suffer from a sort of false democracy, a misguided anti-elitism in the industry. And maybe this is a capitulation to those who would commodify our work. Maybe we need to face up to these sorts of distinctions a bit more honestly and stop expecting that everyone who has anything at all to do with building systems will be skilled as a programmer, should be expected to be able to write code from scratch. It just may not be what they do. Ever. If you want to hire someone who can write code from scratch, the pool of "IT professionals" is not the only place to look, nor is everyone in it a candidate.

 

Plug

By the way, I do want to hire such people, and our hiring process for all technical positions involves a session of actual pair programming, at a workstation, writing real code that has to work, and be shown to work. And the problems we set are a damn sight more complicated that fizz-buzz. If you like the sound of being in the group of people who are successful at such a test, and if you live within, or would be willing to move within, commuting distiance of the inside of the M 25, then why not send me a CV?

6 comments:

Anonymous said...

I tried this is a language that is new to me (Forth). Really, this is my first Forth program. It took me some 30 minutes... But I suppose it would be easier in a language I know -- except that I'd have to lookup how to get the remainder of a number, which isn't something I've used in a while in ny of my programs.

Anyway, here is the forth version, for your amusement... (indentation was removed by blogger, I don't know how to get it to format code)

: div3 ( n -- v) 3 mod 0= ;
: div5 ( n -- v) 5 mod 0= ;
: fizz ( -- ) ." fizz" ;
: buzz ( -- ) ." buzz" ;
: tazz ( n -- ) . ;
: fizzbuzz_single ( n -- ) DUP div3 IF fizz THEN
DUP div5 IF buzz THEN
DUP div3 OVER div5 OR IF DROP
ELSE tazz THEN ;
: fizzbuzz ( -- ) 100 1 ?DO I fizzbuzz_single cr LOOP ;
fizzbuzz

Brian said...

Javascript:
function fizzBuzz() {
for(var i = 1; i <= 100; i++) {
var buffer = '';
if(i % 3 === 0)
buffer += 'Fizz';
if(i % 5 === 0)
buffer += 'Buzz';
if(buffer.length === 0)
buffer += i;
console.log(buffer);
}
}

fizzBuzz();

Unknown said...

C# solution

for(int i = 1; i <= 100; i++)
{
if (i % 15 == 0) Console.WriteLine("fizzBuzz ", i);
else if (i % 3 == 0) Console.WriteLine("fizz ", i);
else if (i % 5 == 0) Console.WriteLine("Buzz ", i);
else Console.WriteLine(i);
}

Unknown said...
This comment has been removed by the author.
Unknown said...


for ($i = 1; $i <= 100; $i++) {
$m3 = $i % 3 == 0;
$m5 = $i % 5 == 0;

if (!$m3 && !$m5) {
echo "$i";
} else {

if ($m3) echo "Fizz";

if ($m5) echo "Buzz";
}

echo "
";
}

Anonymous said...

PL/SQL
declare
p_n integer := 100;
i integer := 1;
p_fb varchar2(16);
begin
while i <= p_n
loop
p_fb := null;
if (mod(i,3) = 0) then p_fb := 'Fizz'; end if;
if (mod(i,5) = 0) then p_fb := p_fb||'Buzz'; end if;
if p_fb is not null then dbms_output.put_line(p_fb);
else dbms_output.put_line(i);
end if;
i := i+1;
end loop;
end;