icaoberg / FizzBuzz

Created Mon, 30 Dec 2024 00:00:00 +0000 Modified Tue, 26 Aug 2025 01:48:20 -0400

While scrolling through Twitter (X.com), I came across this post from Vic Vijayakumar:

This is nothing. As part of our application we asked applicants to submit a solution to FizzBuzz in any language of their choice and most applicants failed it.

The question is very straightforward:

Write a short program that prints each number from 1 to 100 on a new line.

For each multiple of 3, print "Fizz" instead of the number.

For each multiple of 5, print "Buzz" instead of the number.

For numbers which are multiples of both 3 and 5, print "FizzBuzz" instead of the number.

It’s one of those “simple but tricky” questions that shows whether someone can think clearly about control flow and modular arithmetic.


FizzBuzz in Python

This was the first solution I tried—straightforward and clean:

for i in range(1, 101):
    if i % 5 == 0 and i % 3 == 0:
        print("FizzBuzz")
    elif i % 5 == 0:
        print("Buzz")
    elif i % 3 == 0:
        print("Fizz")
    else:
        print(i)

FizzBuzz in Bash

Then I challenged myself to do it in Bash without looking up the docs. I had to recall some syntax, but it worked out:

#!/bin/bash

for i in {1..100}; do
  if (( i % 5 == 0 && i % 3 == 0 )); then
    echo "FizzBuzz"
  elif (( i % 5 == 0 )); then
    echo "Buzz"
  elif (( i % 3 == 0 )); then
    echo "Fizz"
  else
    echo "$i"
  fi
done

FizzBuzz in Octave/Matlab

I don’t currently have Matlab installed, but I tested the logic in Octave:

for i = 1:100
    if mod(i, 5) == 0 && mod(i, 3) == 0
        disp('FizzBuzz');
    elseif mod(i, 5) == 0
        disp('Buzz');
    elseif mod(i, 3) == 0
        disp('Fizz');
    else
        disp(i);
    end
end

What’s Next?

Could I do it in Java or C/C++? Definitely—but I’d need to brush up on the syntax.

It also made me wonder: should I use this as an excuse to try new languages like Rust, Go, or Scala? Each has its quirks, and FizzBuzz might be the perfect warm-up exercise.

Sometimes it’s the simplest challenges that spark the most curiosity.