Waiting for Singularity

Thoughts on science, tech and other preoccupations

All the Buzz About Fizzbuzz

Do companies still use Fizzbuzz to find programmers who can code?

The test may be old news but FizzBuzz is still relevant. Some interesting observations: Global nerdy found that only 40% of the candidates he interviewed could write FizzBuzz, LosTechies believe it provides an accurate window into coding skills, while some engineers think it is plain boring.

StackExchange has suggestions on what to do after you fail the test in an interview. Resources: Project Euler 99 Prolog Puzzles TopCoder Google Code Jam

Find more programming exercises on StackExchange.

FizzBuzz test:

Write a program that prints out the numbers from 1 through 100, but…

For numbers that are multiples of 3, print “Fizz” instead of the number. For numbers that are multiples of 5, print “Buzz” instead of the number For numbers that are multiples of both 3 and 5, print “FizzBuzz” instead of the number.

Shortest Fizzbuzz Scripts

Implemented in Python

for i in range(1,101):print"FizzBuzz"[i*i%3*4:8--i**4%5]or i
for i in range(1,101):print"Fizz"*(i%3<1)+"Buzz"*(i%5<1)or i
for x in range(100): print x%3/2*'Fizz'+x%5/4*'Buzz' or x+1

via  http://koichitamura.blogspot.com/2009/05/python-fizzbuzz.html
and tested on Python v2.7.2

Implemented in Ruby


via http://golf.shinh.org/p.rb?FizzBuzz and tested on Ruby v2.0.0

Implemented in Perl

perl -le'print(($_%3?"":Fizz).($_%5?"":Buzz)or$_)for 1..100'
perl -M5.01 -e 'say+(Fizz)[$_%3].(Buzz)[$_%5]||$_,for 1..100'

via http://www.perlmonks.org/?node_id=602901 tested on v5.12.4

Implemented in PHP


via http://jakespurlock.com/2012/11/php-fizzbuzz-test/ tested on PHP 5

Statistics on Shortest FizzBuzz codes

Language User Size Time Date Statistics
Ruby ksk 50 0.0162 11/02/15 0B / 25B / 24B
Perl shmem 48 0.0918 07/03/02 0B / 22B / 25B
Python Defenestrator 56 0.1151 07/04/20 0B / 35B / 20B
Clojure youz 77 2.7364 11/06/01 0B / 47B / 24B
JavaScript ozy4dm 56 0.0450 07/02/25 0B / 30B / 26B
AWK nn 57 0.0024 08/10/27 0B / 32B / 24B
Bash daishi 41 0.0152 11/02/26 0B / ?B / ?B
Scala lyrical_logical 66 7.8083 11/07/12 0B / 36B / 29B