Iron Coder A CodeNewbie Project

Fizz Buzz - A Study in Variety

Iron Coder Premiere

Fizz Buzz in your choice of language

This past week the Iron Coder team started up here at CodeNewbie. This is a team that tackles coding challenges in the language of their choice. Our first project is winding down to a close and we have had great participation in a wonderfully wide variety of languages.

How to solve Fizz Buzz

The basic idea behind Fizz Buzz is to take a series of numbers and perform replacements on them before outputting them. If the number is divisible by 3, replace it with the word “Fizz”. If the number is divisible by 5, replace it with the word “Buzz”. If it is divisible by both, replace it with “FizzBuzz”.


To determine if an integer is evenly divisible by another integer, a mathematical operation called modulo is used. Modulo is often represented by the “%” character, while division is represented by “/”. This modulo operation, returns the result not of the division itself, but of the remainder after division has been performed. To better understand this, consider the following:

12 / 3 = 4
13 / 3 = 4 Remainder 1
14 / 3 = 4 Remainder 2
15 / 3 = 5

Above you can see that 12 and 15 can be evenly divisible by 3, leaving no remainder. When you divide 13 or 14 by 3 you have a remainder of 1 and 2, respectively

It follows that when you use the modulo operation you get the following results:

12 % 3 = 0
13 % 3 = 1
14 % 3 = 2
15 % 3 = 0

Where the result of the modulo operation is the remainder left over from the integer division.

General Logic

With the modulo operation in hand the rest of the solution falls into place. The general logic of the solution will be a variation on the following:

Loop through a series of numbers
If the number modulo 3 equals 0 output fizz
If the number modulo 5 equals 0 output buzz
If both modulo 3 and 5 equals 0 output fizzbuzz
If none of the above are true, output the number
End Loop

Language Agnosticism

One of the things that I am really enjoying about this first exercise is the wide variety of languages that solutions have been submitted in. We have solutions in the following list of languages:

  • C
  • C++
  • Clojure
  • Go
  • Perl
  • Assembly (via g++ compiler)
  • PHP
  • Javascript
  • Java
  • Ruby
  • Python

I have enjoyed going between these solutions and comparing them not only for the logic and syntax choices made by the developer, but also the choices made by the languages that the solutions are written in.


Let’s take a closer look at a few of the solutions to see how they differ and how they are the same.


I enjoy the way that Kim Still has used functions to organize the conditional logic that determines which value is output. It is very readable and there is a strong sense of organization in the code.

var string = "";

var fizz = function() {
  if (i % 3 === 0) {
  } else {

var buzz = function () {
  if ((i % 5) === 0) {
    string += "Buzz ";
  } else {
    string += i + " ";

var fizzbuzz = function () {
  if ((i % 5) === 0) {
    string += "FizzBuzz ";
  } else {
    string += "Fizz ";

for (i = 1; i <= 100; i++) {



Derek Gustafson’s C based solution uses a switch statement along with a clever logic involving the values resulting from modulo 15, the sum of 3 and 5. The switch statement picks out all of the significant modulo values and defaults the rest to the original number.

int main(void)
	int i;

	for(i=1; i<101; i++)
		switch(i % 15)
			case 0:
			case 5:
			case 10:
			case 3:
			case 6:
			case 9:
			case 12:
				printf("%d\n", i);
	return 0;


PHP is a scripting language used to generate dynamic web content, it was one of the first languages of the web and it is still widely used today. Keyasha Brothern provided the following solution in PHP.


for($i = 1; $i <= 100; $i++) {
   if ($i % 3 == 0 && $i % 5 == 0) {
    echo "FizzBuzz\n";
    } elseif ($i % 3 == 0) {
        echo "Fizz\n";
    } elseif ($i % 5 ==0) {
        echo "Buzz\n";
        echo "$i\n";


Clojure is a language that brings together the power of Lisp with the reliable portability of the Java Virtual Machine. It is a language that looks the most foreign to me, and that makes me want to learn more about it. Derek Gustafson was kind enough to write the following Fizz Buzz solution in Clojure.

(ns fizz-buzz.core

(defn fb_test [x]
    (= (mod x 15) 0) "fizzbuzz"
    (= (mod x 3) 0) "fizz"
    (= (mod x 5) 0) "buzz"
    :else x))

(defn fb_print [x] (println (fb_test x)))

(defn -main
  [& args]
  (dotimes [n 100] (fb_print (+ n 1))))


André Almar wrote the following solution in Go. The Go language is a relative newcomer and this is the first time that I have had a chance to see an example of Go code. Again you see differences from other languages, for instance the for loop that acts more like a traditional while() loop as it does not increment the counter.

package main

import (

func main(){
  number := 1
  for number <= 100 {
    if number % 3 == 0 && number % 5 == 0 {
    } else if number % 3 == 0 {
    } else if number % 5 == 0{
    } else {

    number += 1


I am thrilled to have this opportunity to work with Iron Coders that have such a diverse set of coding backgrounds. This first week they have provided a set of solutions to the Fizz Buzz challenge that exemplify two of the things that I enjoy about this project. These are the different ways that people approach the same problem and the ways that different languages shape the ways that we solve those problems.

All of the solutions submitted were great and I appreciate the team members taking the time to work on them. I hope that you all have a chance to look through the solutions below to see for yourselves the work that they have done.



Modulo -

How to Solve Fizz Buzz -

Iron Coder Premiere -