transmission line noise

home

Fizz Buzz test

05 Feb 2010

Tagged with Work

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

comments powered by Disqus