The FizzBuzz Test – How to Not Fail at Programming

While signing up for Rainstorm (a weekend where college students at really good colleges teach high schoolers short classes), I came across a class that told me I need to be able to code in one of three languages: Python, Java, or Javascript. The interesting thing about this was that the class prerequisites referred me to the FizzBuzz test, stating that students should be able to solve it in one of those three languages. I looked this “FizzBuzz test” up, and was shocked by what I saw.

The FizzBuzz test is a programming challenge designed to filter out programming job applicants who lack any actual ability at coding. And it’s easy. Ridiculously so. The FizzBuzz problem goes as thus:

Write a program that iterates through all integers from 1 to 100 (inclusive) and prints them to the screen. However, if the number is a multiple of three, that number should be replaced with the string “Fizz”. If the number is a multiple of five, it should be replaced with “Buzz”. If the number is a multiple of 15, it should be replaced with “FizzBuzz”.

According to the information I read about this test, 99% of programming job applicants fail this, or at least fail to write an answer within the first five to ten minutes. So, my first thought was to think of a bunch of insanely complex solutions. About a minute in, however, I realized…that’s not necessary. There’s multiple ways to solve this (there normally are for such a simple problem), but a simple one is to use modular arithmetic.

The lovely people reading this blog might not know what that is, but programmers applying to professional jobs should. Simply put, X mod Y is the remainder when X is divided by Y. For example, 8 mod 3 = 2, 7 mod 8 = 7, and 9 mod 3 = 0. If X is divisible by Y, then X mod Y = 0. In Python, the mod operation is symbolized by a percent sign (%).

Here is my Python solution:

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

So, if you can code this in a few minutes, you’re ahead of 99% of programming applicants. If not? Well, now you know, and you’re ahead of 99% of programming applicants. Whenever you, like me, start losing confidence in yourself, just think of how a multitude of programmers can’t do what you can.

Feel free to comment your solutions in another language!

One Comment

  1. Katie January 17, 2022 Reply

Add a Comment

Your email address will not be published. Required fields are marked *