Transmission Line Noise

Fizz Buzz test

Fri, Feb 5, 2010

At a job inter­view the other day i came across the fizz buzz test in the wild for the first time. Sim­ple lit­tle thing but seems to floor people.

In case you have not seen it you out­put the num­bers 1 to 100 but replace those divis­i­ble by 3 with “Fizz” and those divis­i­ble by 5 with “Buzz”.

The real trick is less in the pro­gram­ming than in an easy way to deter­mine the div by 3 & 5 and here the trick is to remem­ber your mod­ulo arithmetic.

So sim­ply put i = 1 to 100

if i%3 == 0 print Fizz

if i%5 == 0 print Buzz

else print i